Facebook Android SDK 4.0:newGraphPathRequest 返回“必须使用活动访问令牌来查询有关当前用户的信息。”

Posted

技术标签:

【中文标题】Facebook Android SDK 4.0:newGraphPathRequest 返回“必须使用活动访问令牌来查询有关当前用户的信息。”【英文标题】:Facebook Android SDK 4.0: newGraphPathRequest returns "An active access token must be used to query information about the current user." 【发布时间】:2015-03-28 23:40:02 【问题描述】:

我已升级到 Facebook android SDK 4.0。我正在尝试请求图形路径:

AccessToken token = AccessToken.getCurrentAccessToken();
GraphRequest req = GraphRequest.newGraphpathRequest(token, 
    "me?fields=name,picture.width(400).height(400)",
    new GraphRequest.Callback()  ... );

我已经检查了代码并验证了token 是一个完全有效的访问令牌,我已经在 Graph API Explorer 中复制并调试了它并且它是有效的。我还尝试通过使用相同的令牌将 me?fields=name,picture.width(400).height(400) 复制粘贴到 Graph API Explorer 来请求完全相同的路径,并且它可以工作。

但是,当我执行请求时:

req.executeAsync();

我在完成处理程序中收到此错误:

"error":"type":"OAuthException","message":"An active access token must be 
used to query information about the current user.","code":2500

我做错了什么?

【问题讨论】:

【参考方案1】:

发现问题。我已将查询字符串参数更改为捆绑参数并将它们从 URL 中删除。有效。在我真正习惯的ios SDK中,没有这样的问题。反正。这是解决方案:

从 URL 中删除参数:GraphRequest req = GraphRequest.newGraphPathRequest(token, "me" ...);

将它们添加为捆绑包。

例子:

Bundle parameters = new Bundle();
parameters.putString("fields", "name,picture.width(400).height(400)");
req.setParameters(parameters);

成功了。

【讨论】:

请记住,GraphRequest 类会在实际请求 URL 中添加参数(例如访问令牌等),因此请不要在“路径”参数中嵌入请求参数。 如果您找到了解决方案,请接受它,因为它在未答复列表中列出。 @AnkitBansal 我现在可以接受,因为 2 天规则我不能接受。

以上是关于Facebook Android SDK 4.0:newGraphPathRequest 返回“必须使用活动访问令牌来查询有关当前用户的信息。”的主要内容,如果未能解决你的问题,请参考以下文章