使用应用程序访问令牌时,Android 中的 OAUTH 访问令牌无效

2023-12-14

正如标题所示,当我尝试请求获取安装了该字段的好友列表时:

"me/friends?Fields=installed&access_token=..."

我的 logcat 中出现以下错误:

"Invalid OAuth access token"

当查看 facebook api 时,我发现安装的程序需要获取应用程序访问令牌。因此,我使用 appId 和 app Secret 生成了应用程序访问令牌:

下面是代码:

try {

 JSONObject obj = Util.parseJson(mFacebook.request("me/friends?fields=installed&access_token=..."));

  Log.d("json Response", obj.toString());
  JSONArray array = obj.optJSONArray("data");
  if (array != null) {
                      for (int i = 0; i < array.length(); i++) {
                        //  String name = array.getJSONObject(i).getString("name");

                          String id = array.getJSONObject(i).getString("id");

                          Log.d("Friends: ",id);
                      }
                  } 
  }catch (Exception e){
    Log.d("Friends:", e.getMessage());
  }

任何人有任何想法为什么要这样做,我已经寻找了很长时间。

Cheers


认证后您得到的是App Access Token。

引用:Authenticating as an App allows you to obtain an access token which allows you to make request to the Facebook API on behalf of an App rather than a User. This is useful, for example to modify the parameters of your App, create and manage test users, or read your application's insights for example. App access tokens can also be used to publish content to Facebook on behalf of a user who has granted a publishing permission to your application

from 脸书文档.

您的案例需要的是用户访问令牌。参考this。 用户需要进行身份验证并授予对您的应用程序的访问权限,以便您可以访问他的好友列表。

EDIT

为了检查单个用户,URL 是https://graph.facebook.com/{uid}?fields=已安装&access_token=

您正在尝试获取用户好友列表,然后检查该应用程序是否已安装。我认为没有用户访问令牌就不可能获取用户朋友列表。

EDIT 2

假设从你的评论中你有朋友的名单。然后您无需调用每个用户,而是可以使用 FQL。

https://graph.facebook.com/fql?q=SELECT uid,is_app_user from user where uid IN (uid1,uid2)

如果您有用户访问令牌,那么您可以直接执行此操作。

https://graph.facebook.com/fql?q=SELECT uid,is_app_user from user where uid IN (SELECT uid2 FROM friend WHERE uid1 = me())

希望这能解决您的问题。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用应用程序访问令牌时,Android 中的 OAUTH 访问令牌无效 的相关文章

随机推荐