在 Facebook SDK 4 中创建请求 (Android)

Create a Request in Facebook SDK 4 (Android)

据我了解,Facebook SDK v4 不再使用 Session,但我在他们的 Graph API 文档中读到,session 仍然用于创建 Request

https://developers.facebook.com/docs/graph-api/using-graph-api/v2.3

/* make the API call */
new Request(
    session,
    "/me",
    null,
    HttpMethod.GET,
    new Request.Callback() {
        public void onCompleted(Response response) {
            /* handle the result */
        }
    }
).executeAsync();

我很困惑,我怎样才能得到请求的会话?使用 Facebook Graph 获取用户配置文件数据的任何最新示例 API?

如有任何建议,我们将不胜感激。

在 Facebook 开发者页面上发布了更新日志和升级 post。在您的情况下,这是一个选项:

GraphRequest request = GraphRequest.newMeRequest(accessToken, new GraphRequest.GraphJSONObjectCallback() {
            @Override
            public void onCompleted(JSONObject user, GraphResponse response) {
                /* handle the result */
            }
    }).executeAsync();

顺便说一下,他们指定了这个:

By default a newMeRequest method fetches default fields from a user object. If you need any additional fields, or want to reduce the response payload for performance reasons, you can add a fields parameter and request specific fields.

例如:

GraphRequest request = GraphRequest.newMeRequest(
    accessToken,
    new GraphRequest.GraphJSONObjectCallback() {
        @Override
        public void onCompleted(
               JSONObject object,
               GraphResponse response) {
            // Application code
        }
    });
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,link");
request.setParameters(parameters);
request.executeAsync();

希望我的回答对您有所帮助,这是我在 Whosebug 中的第一个回答。你好。

参考:Facebook Android SDK Upgrading