"无法解析facebook Graph API的符号'Request`"错误

Sha*_*zal 3 java android facebook-graph-api facebook-android-sdk android-studio

我将最新的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();
Run Code Online (Sandbox Code Playgroud)

但我无法导入Request类,我收到错误Cannot resolve symbol请求``.

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

谢谢.

The*_*bhi 6

除了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();
Run Code Online (Sandbox Code Playgroud)

  • 完善!谢谢 - 我正在寻找SDK 4的新代码.看来Facebook还没有更新他们的SDK 4指南并使用旧的例子.我希望他们在实现SDK 4. +1之前更新他们的所有示例 (2认同)

小智 5

Request类已重命名为GraphRequest.