0

私はこのスニペットを持っています

  AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(mFacebook);
                    Bundle bundle = new Bundle();
                    bundle.putString("fields", "birthday");
                    mAsyncRunner.request("me/friends", bundle, new FriendListRequestListener());

どういうわけか機能します。つまり、すべての友達からIDを読み取ることができます。しかし、すべてを読みたいのですが、どうすればそれができますか?

    String _error = null;

        JSONObject json = Util.parseJson(response);
        final JSONArray friends = json.getJSONArray("data");

        for (int i = 0; i < friends.length(); i++) {
            Log.v("id:", "id= "+friends.get(i).toString());
         }

友達に関する情報を取得し、その情報を読むにはどうすればよいですか

これが鍵だと思います。これは私が見つけた例からのもので、正常に動作します

bundle.putString("fields", "birthday");

しかし、たとえば、うまくいきません

bundle.putString("fields", "friends_relationships");

---編集1---------------

アクセス許可のコード

    mFacebook.authorize(Example.this, new String[] {"offline_access", "user_interests", "friends_interests","friends_relationships","friends_relationship_details"},new DialogListener() {
        @Override
        public void onComplete(Bundle values) {}

        @Override
        public void onFacebookError(FacebookError error) {}

        @Override
        public void onError(DialogError e) {}

        @Override
        public void onCancel() {}
   });

-------------- 編集 2 --------------

{"エラー":{"メッセージ":"アクティブなアクセス トークンを使用して、現在のユーザーに関する情報を照会する必要があります。","type":"OAuthException","code":2500}}

4

4 に答える 4

1

ほとんどの場合、Graph API が賢明な選択です。フレンド情報を取得するには、まずユーザーからいくつかの拡張アクセス許可を収集する必要があります。次に、基本的な情報以外のより多くの情報を取得できます。

以下は、友人のさまざまな種類の情報に関連する拡張権限のリストです。

friends_about_me        
friends_activities      
friends_birthday
friends_checkins        
friends_education_history       
friends_events
friends_games_activity      
friends_groups      
friends_hometown
friends_interests       
friends_likes       
friends_location
friends_notes       
friends_online_presence     
friends_photo_video_tags 
friends_photos      
friends_relationship_details        
friends_relationships
friends_religion_politics       
friends_status      
friends_subscriptions
friends_videos      
friends_website     
friends_work_history

facebook.authorize(this, new String[] {"offline_access", "user_interests", "friends_interests"},

編集 :-

アプリが機能するためにこれ以上の基本情報が必要な場合は、ユーザーに特定の権限を要求する必要があります。これは、パーミッションの String[] を authorize メソッドに渡すことによって実現されます。次の例は、ユーザーの電子メール アドレスへのアクセスを要求し、拡張アクセス トークンを取得し、ある場所でユーザーをチェックインする方法を示しています。

facebook.authorize(this, new String[] { "email", "publish_checkins" },

      new DialogListener() {
           @Override
           public void onComplete(Bundle values) {}

           @Override
           public void onFacebookError(FacebookError error) {}

           @Override
           public void onError(DialogError e) {}

           @Override
           public void onCancel() {}
      }
);

詳しくはこちらをご覧ください。

編集 :-

 mAsyncRunner.request("me/friends?fields=id,name,birthday,relationship_status", new FriendListRequestListener());

JSONObject json = Util.parseJson(response);
final JSONArray friends = json.getJSONArray("data");

for(int i=0;i<friends.length();i++)
{
    JSONObject object = friends.getJSONObject(i);
    Log.i("------------------ Id",object.getString("id"));
    Log.i("------------------ Name",object.getString("name"));
    Log.i("------------------ RelationShip",object.getString("relationship_status"));
 }
于 2012-09-17T12:19:49.227 に答える
0

友達関係には個別の権限があります。アクセス許可のドキュメントを確認してください。

あなたは要求したいと思うでしょう -

  • friends_relationships
  • friends_relationship_details
于 2012-09-17T12:19:30.287 に答える
-1

これを試して :

 Bundle params = new Bundle();
 params.putString("fields", "name, picture, location");
    mAsyncFacebook.request("me/friends",params, new RequestListener(){
        @Override
        public void onComplete(String response, Object object) {
            JSONObject jsonObject = null;
            try {
                jsonObject = new JSONObject(response);
            } catch (JSONException e) {
                Log.d(TAG,"Exception :"+e);
            }

        }
   }

キーについて知るには、このリンクを参照してください: https://developers.facebook.com/docs/authentication/permissions/

于 2012-09-17T12:21:55.137 に答える