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

Can*_*ğlu 3 android facebook facebook-android-sdk facebook-sdk-4.0

我已升级到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() { ... });
Run Code Online (Sandbox Code Playgroud)

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

但是,当我执行请求时:

req.executeAsync();
Run Code Online (Sandbox Code Playgroud)

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

{"error":{"type":"OAuthException","message":"An active access token must be 
used to query information about the current user.","code":2500}}
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

Can*_*ğlu 6

发现了问题.我已将查询字符串参数更改为捆绑参数,并将其从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);
Run Code Online (Sandbox Code Playgroud)

有效.