当前位置: 代码迷 >> Android >> Android Facebook获取完整的用户个人资料
  详细解决方案

Android Facebook获取完整的用户个人资料

热度:61   发布时间:2023-08-04 11:53:14.0

我无法使用Facebook sdk获取完整的用户个人资料。 我正在尝试通过以下链接从Facebook的图API中检索用户节点。 我只收到一些字段(有点有限的配置文件)

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

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

获得访问令牌后,将调用“ / me”端点。 我获得了相应用户的Facebook用户ID。 然后,使用以下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();

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

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

我目前只能检索ID,电子邮件,名字,性别,姓氏,链接,语言环境,名称,时区和已验证字段

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

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();
  相关解决方案