繁体   English   中英

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

[英]Invalid OAUTH access token, when using an application access token, Android

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

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

我在logcat中收到以下错误:

"Invalid OAuth access token"

当查看facebook api时,我看到已安装的需要带一个应用程序访问令牌。 因此,我使用以下命令使用appId和app Secret生成了应用程序访问令牌:

https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id=APP_ID&client_secret=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());
  }

任何人任何想法为什么这样做我一直在寻找。

干杯

身份验证后得到的是App Access令牌。

报价: 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 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

来自facebook docs

您需要的是用户访问令牌。 请参考 用户需要验证身份并授予对您应用的访问权限,因为您可以访问其朋友列表。

编辑

要检查单个用户,URL为https://graph.facebook.com/ {uid}?fields = installed&access_token = <ACCESS_TOKEN>

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

编辑2

根据您的评论,假设您有frind的列表。 然后,您无需为每个用户呼叫,而可以使用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())

希望这能解决您的问题。

不要请求/ / 朋友 -因为使用应用访问令牌,API不会知道“我”应该是谁-而是请求/ 用户ID / 朋友

抱歉,我以前做错了–方式是使用用户访问令牌 ,并根据/ me / friends设置请求…

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM