ANDROID FACEBOOK SDK-4.0:当我在 GraphRequest.newGraphPathRequest 中使用“/me?fields=age_range”时出现错误

ANDROID FACEBOOK SDK-4.0: I get an error when i use "/me?fields=age_range" in my GraphRequest.newGraphPathRequest

  1. 我需要从 facebook 获取 age_range
  2. 当我在 GraphRequest.newGraphPathRequest 中使用 /me?fields=age_range 时,出现错误。
  3. 错误是graphObjectreturnsnull。我试过使用 /me 并且它有效我得到了正确的用户数据虽然当我使用 /me?fields=age_range 我得到这个错误。

Testing﹕ {Response: responseCode: 400, graphObject: null, error: {HttpStatus: 400, errorCode: 2500, errorType: OAuthException, errorMessage: An active access token must be used to query information about the current user.}}


这是我一直在尝试修复的代码。

         GraphRequest request = GraphRequest.newGraphPathRequest(accessToken,
                        "/me?fields=age_range",
                        new GraphRequest.Callback() {
                            @Override
                            public void onCompleted(GraphResponse graphResponse) {

                                Log.v("Testing", graphResponse.toString());


                            }
                        });
                request.executeAsync();

您不应将“/me?fields=age_range”作为您的 GraphRequest 中的路径。

而是只使用“/me”作为路径,然后创建一个新的Bundle,并将"fields"作为键,将"age_range"作为字符串值,并设置新的bundle 作为 GraphRequest 的参数。

GraphRequest request = ...
...
Bundle params = new Bundle();
params.putString("fields", "age_range");
request.setParameters(params);
request.executeAsync();
...