Facebook Graph API出现"Cannot resolve symbol `Request`"错误

3

我将最新的Facebook SDK 4.0.1导入到Android Studio项目中。我想按照Graph API参考文档列出的基本步骤进行Graph API调用。

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

但我无法导入Request类,我遇到了错误无法解析符号Request。

如何解决这个问题?我需要导入其他库来使用Graph API吗?

谢谢。

3个回答

6
除了将Request更改为GraphRequest,将Response更改为GraphResponse之外,现在不再传递session,而是在构造函数中传递AccessToken.getCurrentAccessToken或accessToken。因此,您的查询将如下所示:
  GraphRequestAsyncTask graphRequest = new GraphRequest(
                    AccessToken.getCurrentAccessToken(),
                    "/{user-id}/",
                    null,
                    HttpMethod.GET,
                    new GraphRequest.Callback() {
                        public void onCompleted(GraphResponse response) {
        /* handle the result */
                        }
                    }
            ).executeAsync();

2
太好了!谢谢 - 我一直在寻找SDK 4的新代码。看起来Facebook还没有更新他们的SDK 4指南,仍在使用旧的示例。我希望他们在发布SDK 4之前更新所有的示例。+1 - Simon
非常有帮助。谢谢。 - Linga

5

Request类已被重命名为GraphRequest。


0

正如 @Gokhan 所解释的那样,现在该类被称为 GraphRequest

Facebook SDK 4.x 是对 3.x 的重大更新,有很多变化,您应该查看 Facebook 的升级指南


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接