“无法解析符号`请求`”错误的Facebook图形API
问题描述:
我将最新的Facebook SDK 4.0.1
纳入Android Studio项目。我想要做的基本的图形API调用上Graph API reference“无法解析符号`请求`”错误的Facebook图形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
类,我得到错误Cannot resolve symbol
Request``。
如何解决此问题?我是否需要导入一些其他库来使用Graph API?
谢谢。
答
Request类已重命名为GraphRequest。
答
正如@Gokhan所解释的,该类现在称为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();
完美!谢谢 - 我正在寻找SDK 4的新代码。看起来Facebook没有更新SDK 4的指南,并且使用了旧的示例。我希望他们在实现SDK 4之前更新所有示例。+1 – Simon
@Simon是的。他们的文档尚未更新。 – TheOddAbhi
真的有帮助。谢谢。 –