【问题标题】:Create a Request in Facebook SDK 4 (Android)在 Facebook SDK 4 (Android) 中创建请求
【发布时间】:2015-10-28 22:42:36
【问题描述】:

据我了解,Facebook SDK v4 不再使用会话,但我在他们的 Graph API 文档中阅读,会话仍然用于创建请求

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();

这让我很困惑,我怎样才能获得 Request 的会话?使用 Facebook Graph API 获取用户个人资料数据的任何最新示例?

感谢任何建议。

【问题讨论】:

    标签: android facebook facebook-graph-api


    【解决方案1】:

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

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

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

    默认情况下,newMeRequest 方法从用户对象中获取默认字段。如果您需要任何额外的字段,或者出于性能原因想要减少响应负载,您可以添加字段参数并请求特定字段。

    例如:

    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();
    

    希望我的回答对您有所帮助,这是我在 stackoverflow 中的第一个回答。问候。

    参考:Facebook Android SDK Upgrading

    【讨论】:

      猜你喜欢
      • 2015-07-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-05
      • 2014-10-18
      • 1970-01-01
      • 1970-01-01
      • 2013-06-11
      相关资源
      最近更新 更多