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

时间:2012-06-19 11:38:32

标签: android facebook oauth access-token

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

"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 个答案:

答案 0 :(得分: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。 用户需要对您的应用进行身份验证和授予访问权限,才能访问其朋友列表。

修改

为了检查单个用户,网址是 https://graph.facebook.com/ {UID}字段=安装&安培; =的access_token&LT; ACCESS_TOKEN&gt;

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

编辑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())

希望这能解决你的问题。

答案 1 :(得分:0)

请勿/ / 朋友 - 因为使用应用访问令牌,API无法知道“我”应该是谁 - 请求/ 用户ID / 朋友

抱歉,我以前错了 - 要走的路是使用用户访问令牌,只是针对/ me / friends设置请求......