"Cannot resolve symbol `Request`" Facebook 图 API 错误

"Cannot resolve symbol `Request`" error for facebook Graph API

我将最新的 facebook SDK 4.0.1 包含到 Android Studio 项目中。我想进行 Graph API reference

中列出的基本 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 class,我收到错误 Cannot resolve symbolRequest``。

如何解决这个问题?我是否需要导入其他库才能使用 Graph API?

谢谢。

请求 class 已重命名为 GraphRequest。

正如@Gokhan 所解释的,class 现在被称为 GraphRequest

Facebook SDK 4.x 是对 3.x 的重大更新,有许多更改,您应该查看 Facebook 的 upgrading guide

Request 更改为 GraphRequest 外,Response 更改为 GraphResponse,现在不再传递 session,而是传递 AccessToken.getCurrentAccessToken or accessToken 在构造函数中。所以你的查询将是这样的:

  GraphRequestAsyncTask graphRequest = new GraphRequest(
                    AccessToken.getCurrentAccessToken(),
                    "/{user-id}/",
                    null,
                    HttpMethod.GET,
                    new GraphRequest.Callback() {
                        public void onCompleted(GraphResponse response) {
        /* handle the result */
                        }
                    }
            ).executeAsync();