Facebook sdk朋友返回我的id而不是他们的

时间:2015-09-18 11:08:43

标签: android facebook facebook-graph-api

我正在使用最新的facebook sdk。我使用以下代码来吸引使用我的应用的朋友:

  private void getUserFriendsFacebookIds() {

        GraphRequest request = new GraphRequest(
                AccessToken.getCurrentAccessToken(),
                "/me/friends",
                null,
                HttpMethod.GET,
                new GraphRequest.Callback() {
                   public void onCompleted(GraphResponse response) {
                   /* handle the result */
                   Log.d("-@-", "graph response " + response.getJSONObject());

                   try
                   {
                   JSONObject data=response.getJSONObject();
                 JSONArray  users = data.getJSONArray("data");

                 if(users!=null)
                 {                 
                 for(int i=0;i<users.length();i++)
                 {

                     JSONObject object = users.getJSONObject(i);

                       String name=object.getString("name");
                       String id=object.getString("id");
                       names.add(name);
                       fbid.add(id);

                     //  Toast.makeText(getApplicationContext(),
                        //      name, Toast.LENGTH_SHORT).show(); 
                 }


                 FacebookLazyImageLoadAdapter adapter=new FacebookLazyImageLoadAdapter(Friends.this,names,fbid);

                friends.setAdapter(adapter);
                adapter.notifyDataSetChanged();
                 }
                 else
                 {
                     Toast.makeText(getApplicationContext(),
                                "Connection error", Toast.LENGTH_SHORT).show(); 
                 }
                   }
                   catch(Exception ex)
                   {
                       Toast.makeText(getApplicationContext(),
                               "Connection error", Toast.LENGTH_SHORT).show();
                   }
    if (response.getError() != null) {
            Log.e(TAG, "User data error: " + response.getError(), response.getError().getException());
        } else {
            //setUserFriends(response.getRawResponse());
        }
            }
          }
        );

        Bundle parameters = new Bundle();
        parameters.putString("fields", "id,name");
        request.setParameters(parameters);
        request.executeAsync();

    }  

问题是,在logcat中,它返回我的facebook id而不是他们的,尽管响应是返回他们的名字,但所有id都是相同的(我的id)。有什么帮助吗?

0 个答案:

没有答案