【问题标题】:Android Facebook Get Complete User ProfileAndroid Facebook 获取完整的用户资料
【发布时间】:2016-01-24 11:15:02
【问题描述】:

我无法使用 Facebook sdk 获取完整的用户个人资料。我正在尝试参考以下链接从 Facebook 的图形 API 中检索用户节点。我只收到几个字段(有点像有限的个人资料)

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

我首先使用以下行进行登录。

    LoginManager.getInstance().logInWithReadPermissions(getActivity(), Arrays.asList("public_profile", "user_friends"));

一旦我有了访问令牌,我就会调用“/me”端点。我得到了相应用户的 Facebook 用户 ID。使用此 ID,然后我使用以下代码调用“/{user-id}”端点。

   new GraphRequest(
            AccessToken.getCurrentAccessToken(),
            "/" + userProfile.getId(),
            null,
            HttpMethod.GET,
            new GraphRequest.Callback() {
                public void onCompleted(GraphResponse response) {
                    Log.d(TAG, response.getRawResponse());
                }
            }
    ).executeAsync();

但是,返回的字段是有限的,并且不包含下面链接中提到的完整字段集。

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

我如何检索与用户相关的完整数据集,包括上面链接中提到的朋友列表、年龄等?

我只能检索 id、email、first_name、gender、last_name、link、locale、name、timezone 和经过验证的字段,目前。

【问题讨论】:

    标签: android facebook facebook-graph-api


    【解决方案1】:

    我想出了如何检索必填或特定字段。默认情况下,不返回来自特定节点的所有字段。您需要通过将它们作为参数传递来指定它们,如下所示。

    GraphRequest graphRequest = new GraphRequest(
                AccessToken.getCurrentAccessToken(),
                "/me",
                null,
                HttpMethod.GET,
                new GraphRequest.Callback() {
                    public void onCompleted(GraphResponse response) {
                        Log.d(TAG, response.getRawResponse());
    
    
                    }
                }
        );
        Bundle parameters = new Bundle();
        parameters.putString("fields", "id,email,first_name,gender,last_name,link,locale,name,timezone,updated_time,verified,age_range,friends");
        graphRequest.setParameters(parameters);
        graphRequest.executeAsync();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-10
      • 2017-08-27
      • 1970-01-01
      • 2011-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多