首页 文章

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

提问于
浏览
1

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

"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());
  }

任何一个想法,为什么它这样做我一直在寻找年龄 .

干杯

2 回答

  • 1

    身份验证后您获得的是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

    来自facebook docs .

    您的案例需要的是用户访问令牌 . 请参阅this . 用户需要对您的应用进行身份验证和授予访问权限,以便您可以访问其朋友列表 .

    EDIT

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

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

    EDIT 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())

    希望这能解决你的问题 .

  • 0

    不要请求/我/朋友 - 因为有了应用程序访问令牌,API将无法知道“我”应该是谁 - 请求/用户ID /朋友 .

    对不起,我以前错了 - 走的路是 user access token ,只是设置请求/我/朋友...

相关问题