使用 Facebook Graph API 获取所有用户好友 - Android

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23850807/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 07:32:07  来源:igfitidea点击:

Get ALL User Friends Using Facebook Graph API - Android

androidfacebookfacebook-graph-api-v2.0facebook-friends

提问by David

I'm trying to get all friends, of a user that logged into my application.

我正在尝试获取登录我的应用程序的用户的所有朋友。

I can't use this API [friends]:

我不能使用这个 API [朋友]:

https://developers.facebook.com/docs/graph-api/reference/v2.0/user/friends

https://developers.facebook.com/docs/graph-api/reference/v2.0/user/friends

Because this API only returns any friends who have used the app making the request.

因为这个 API 只返回任何使用该应用程序发出请求的朋友。

So I found this API [friendlist]:

所以我找到了这个 API [friendlist]:

https://developers.facebook.com/docs/graph-api/reference/v2.0/friendlist

https://developers.facebook.com/docs/graph-api/reference/v2.0/friendlist

Followed this answer, I got the friendlist list.

按照这个答案,我得到了朋友名单。

But I'm getting empty list when trying to get friendlist's members:

但是在尝试获取朋友列表的成员时,我得到了空列表:

new Request(
            session,
            "/2692926356774/members",
            null,
            HttpMethod.GET,
            new Request.Callback()
            {
                public void onCompleted(Response response)
                {
                    /* handle the result */
                    Log.e(LOG_TAG,"Members: " + response.toString());
                }
            }
    ).executeAsync();

2692926356774is my Acquaintances list id, I tried few other id's with the same result.

2692926356774是我的Acquaintances list id,我尝试了其他几个 ID,结果相同。

回答by Simon Cross

In v2.0 of the Graph API, calling /me/friendsreturns the person's friends who also use the app.

在 Graph API v2.0 中,调用/me/friends返回也使用该应用程序的人的朋友。

In addition, in v2.0, you must request the user_friendspermission from each user. user_friendsis no longer included by default in every login. Each user must grant the user_friendspermission in order to appear in the response to /me/friends. See the Facebook upgrade guidefor more detailed information, or review the summary below.

另外,在 v2.0 中,您必须向user_friends每个用户请求权限。user_friends不再默认包含在每次登录中。每个用户都必须授予user_friends权限才能出现在对 的响应中/me/friends。有关更多详细信息,请参阅Facebook 升级指南,或查看下面的摘要。

The /me/friendlistsendpoint and user_friendlistspermission are not what you're after. This endpoint does not return the users friends - its lets you access the lists a person has made to organize their friends. It does not return the friends in each of these lists. This API and permission is useful to allow you to render a custom privacy selector when giving people the opportunity to publish back to Facebook.

/me/friendlists端点和user_friendlists权限不是你追求的。此端点不会返回用户的朋友 - 它允许您访问一个人为组织他们的朋友而制作的列表。它不会返回每个列表中的朋友。此 API 和权限有助于您在让人们有机会向 Facebook 发回消息时呈现自定义隐私选择器。

If you want to access a list of non-app-using friends, there are two options:

如果您想访问不使用应用程序的朋友列表,有两种选择:

  1. If you want to let your people tag their friendsin stories that they publish to Facebook using your App, you can use the /me/taggable_friendsAPI. Use of this endpoint requires review by Facebookand should only be used for the case where you're rendering a list of friends in order to let the user tag them in a post.

  2. If your App is a Game AND your Game supports Facebook Canvas, you can use the /me/invitable_friendsendpoint in order to render a custom invite dialog, then pass the tokens returned by this API to the standard Requests Dialog.

  1. 如果您想让您的用户在他们使用您的应用发布到 Facebook 的快拍中标记他们的朋友,您可以使用/me/taggable_friendsAPI。使用此端点需要 Facebook ,并且仅应用于呈现好友列表以便用户在帖子中标记他们的情况。

  2. 如果您的应用程序是游戏并且您的游戏支持 Facebook Canvas,您可以使用/me/invitable_friends端点来呈现自定义邀请对话框,然后将此 API 返回的令牌传递给标准请求对话框。

In other cases, apps are no longer able to retrieve the full list of a user's friends (only those friends who have specifically authorized your app using the user_friendspermission).

在其他情况下,应用程序不再能够检索用户好友的完整列表(只有那些使用user_friends权限专门授权您的应用程序的好友)。

For apps wanting allow people to invite friends to use an app, you can still use the Send Dialog on Webor the new Message Dialog on iOSand Android.

对于希望允许人们邀请朋友使用应用程序的应用程序,您仍然可以使用Web 上发送对话框iOSAndroid上的新消息对话框