Facebook SDK 3.22(android) - 我/朋友返回错误用户的朋友ID

时间:2015-01-23 17:32:22

标签: android facebook facebook-graph-api

我希望我的应用程序获取已经使用该应用程序的用户朋友的ID和名称,并通过名称找到我需要的ID。然后我想使用参数“TO”的feed对话框发布到朋友的墙上。我觉得这很容易。只需使用me/friends即可。请求:

if(session.getState().isOpened()){
        Log.i(TAG, "Creating request");
        Request friendRequest =  new Request(session, "/me/friends", null, HttpMethod.GET, new Request.Callback() {
            public void onCompleted(Response response) {
                Log.w(TAG, "Complete!" + response.toString());

                JSONArray usersArrays = new JSONArray();

                try {
                    Log.i(TAG, "Converting to userObject");
                    usersArrays = response.getGraphObject().getInnerJSONObject().getJSONArray("data");

                    for (int i = 0; i < usersArrays.length(); i++){
                        Log.i(TAG, "Reading " + i + " user");
                        JSONObject user = usersArrays.getJSONObject(i);

                        Log.i(TAG, "Getting name and id");
                        String userId = user.getString("id");
                        String userName = user.getString("name");

                        Log.i(TAG, "Now checking: " + userName + " with id: " + userId);

                        if (userName.equals(name)){
                            Log.w(TAG, "He was found! Here is his id: " + userId);
                            postToWall(userId);

                        } else if (i == (usersArrays.length() - 1)){
                            Log.e(TAG, name + " does not use the app yet!");
                            //no ways
                        }
                    }

                } catch (JSONException e) {
                    Log.e(TAG, "Error: " + e);
                    Toast.makeText(context, "Error", Toast.LENGTH_LONG).show();

                }
            }
        }
        );

        Log.i(TAG, "Sending request");
        friendRequest.executeAndWait();

以下是我的回复:

{Response:  responseCode: 200, graphObject: GraphObject{graphObjectClass=GraphObject, state={"summary":{"total_count":46},"data":[{"id":"383791018465143","name":"Friend Name"}],"paging":{"next":"..."}}}, error: null, isFromCache:false}

然后我找到了this网站,并决定找出朋友的身份。它不一样。

使用Feed对话框时,我的应用程序因Facebook错误而崩溃:incorrect user。我该怎么办呢?

提前谢谢谢尔盖

1 个答案:

答案 0 :(得分:1)

作为@MingLi sais,我无法获得用户朋友的Facebook ID