2011-12-01 8 views
6

私は、Android用Facebook SDKを自分のアプリで使用しています。通知を取得するためにSDKコードを使用する方法に関するサンプルやドキュメントを見つけることができないようです。私は "manage_notifications"のアクセス許可が設定されているので、.request()メソッドを使用する必要があると仮定していますが、graphPathパラメータではわかりません。Android Facebook SDK - Facebook通知を照会する方法

Android用Facebook SDKを使用してFacebook通知を取得する方法の例はありますか?

答えて

3

他の回答が参考になっですが、私が探していたことだったの正しい拡張権限ですAndroidコードの例。私はそれを理解してここに掲載しました。以下のコードは、ログイン/認証されたユーザーの通知を取得します。

//Initialze your Facebook object, etc. 
Facebook _facebook = ... 
... 
Bundle bundle = new Bundle(); 
bundle.putString(Facebook.TOKEN, _accessToken); 
String result = _facebook.request("me/notifications", bundle, "GET"); 

次に、 "result"という文字列を解析する必要があります。それはjson形式です。次のような例が表示されます。

JSONObject jsonObjectResults = new JSONObject(result); 
JSONArray jsonNotificationDataArray = jsonObjectResults.getJSONArray("data"); 
for (int i=0;i<jsonNotificationDataArray.length();i++) 
{ 
    JSONObject jsonNotificationData = jsonNotificationDataArray.getJSONObject(i); 
    if (_debug) Log.v("Title: " + jsonNotificationData.getString("title")); 
} 

この情報は他の人に見てほしいと思います。

+0

このコードはどこに追加すればいいですか?onCreate()またはonComplete()内 – Vivekanand

+0

@Vivekanandこのコードは、Facebook通知のjsonデータを照会する場所に追加する必要があります。 –

+0

_facebookオブジェクトは償却されます:) –

1

デフォルトでは、/ USER_ID/notificationsエンドポイントには未読の通知のみが含まれます(つまり、Facebook.comのトップラインの3番目のジュエルが点灯し、その内部に赤い数字がある場合は戻り値があります)

あなたはまた、ユーザがすでに読んでいるの通知を含める場合は、/USER_ID/notifications?include_read=1にリクエストすることができます - manage_notificationsこの

+0

、あなたに非常に参考に感謝され、この情報を取得する方法です。しかし、私はrequest()メソッドに関するAndroid固有のコードを探していました。 、facebook.authorize(この \t \t \t \t \t新しいString [] { "電子メール"、 "publish_stream"、 "manage_notifications"} ..: –

+0

あなたはどのようにpermission.Thankyou.iがこれを使用してみましたmanage_notificationを追加する方法を教えてくださいすることができます –

0

FQLクエリを使用することもできます。クエリの形式は

SELECT notification_id, sender_id, title_html, body_html, href 
FROM notification 
WHERE recipient_id=userid 
AND is_unread = 1 
AND is_hidden = 0 



がBaseRequestListenerを実装して、リスナーのこのクエリの結果は、onCompleteのに受信することができます詳細http://developers.facebook.com/docs/reference/fql/notification/

()のために、このページを参照してくださいになります。

1

Facebook SDK 3.0のセッションオブジェクトを確認して、セッションが開かれていることを確認できます。 その後、あなたは次のコードの助けを借りて、JSONデータを取得することができます。

Session session = Session.getActiveSession(); 
    if (session.isOpened()) 
    { 
     //access_token = session.getAccessToken(); 
     Request graphRequest = Request.newGraphPathRequest(session, "me/home", new  
     Request.Callback() 
    { 
    public void onCompleted(Response response) 
      { 
       //Create the GraphObject from the response 
       GraphObject responseGraphObject = response.getGraphObject(); 

       //Create the JSON object 
       JSONObject json = responseGraphObject.getInnerJSONObject(); 
       Log.i("JSON", json.toString()); 
       try 
       { 
        YOUR_JSON_ARRAY= json.getJSONArray("data"); 
       } 
       catch (JSONException e) 
       { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
       } 
      } 
     }); 
    Request.executeBatchAsync(graphRequest); 
    } 
+1

これは私が探しているもののようです。私は時間があるときに物事を試してみましょう。 –

0

これは私が通知

final Session session =Session.getActiveSession(); 
      if(session.isOpened()){ 
       String aaa=new String(); 
       aaa="SELECT title_text,updated_time FROM notification WHERE recipient_id=me() AND is_unread=1"; 
       Bundle params = new Bundle(); 
       params.putString("q", aaa); 
        new Request(session,"/fql",params,HttpMethod.GET,new Request.Callback() { 
           public void onCompleted(Response response) { 
            try 
            { 
             GraphObject go = response.getGraphObject(); 
             JSONObject jso = go.getInnerJSONObject(); 
             JSONArray arr = jso.getJSONArray("data"); 
             String splitting=arr.toString().replaceAll("\\\\|\\{|\\}|\\[|\\]", ""); 
             String[] arrayresponse=splitting.split("\\,"); 
             String s = ""; 
             for (int i = 0; i < arrayresponse.length; i++) { 
              if (arrayresponse[i].length()>13){ 
               if (arrayresponse[i].substring(1,13).equals("updated_time")) 
                s+="* "+getDate(Long.valueOf(arrayresponse[i].substring(15,arrayresponse[i].length())))+"\n"; 
               else 
                s+=" "+arrayresponse[i].substring(14,arrayresponse[i].length()-1)+"\n\n"; 

              } 
             } 
             text2.setVisibility(View.VISIBLE); 
             NotificationMessage.setVisibility(View.VISIBLE); 
             NotificationMessage.setMovementMethod(new ScrollingMovementMethod()); 
             NotificationMessage.setText(s); 
             readMailBox(session); 

            }catch (Throwable t) 
            { 
             t.printStackTrace(); 
            } 


           } 
          } 
        ).executeAsync(); 
      } 
      else{ 
    //   NotificationMessage.setVisibility(View.INVISIBLE); 
       Log.i(TAG, "Logged out..."); 
      } 
    } 
関連する問題