[英]Invalid OAUTH access token, when using an application access token, Android
As the title says, when I try to request to get the friends list with the field installed: 如标题所示,当我尝试请求获取安装了该字段的朋友列表时:
"me/friends?Fields=installed&access_token=..."
I get the following error in my logcat: 我在logcat中收到以下错误:
"Invalid OAuth access token"
When looking on the facebook api I see that installed needs to take an application access token. 当查看facebook api时,我看到已安装的需要带一个应用程序访问令牌。 So I generated the application access token using the appId and app Secret using:
因此,我使用以下命令使用appId和app Secret生成了应用程序访问令牌:
https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id=APP_ID&client_secret=APP_SECRET https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id=APP_ID&client_secret=APP_SECRET
Below is the code: 下面是代码:
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());
}
Any one any ideas why its doing this I have been searching for ages. 任何人任何想法为什么这样做我一直在寻找。
Cheers 干杯
What you are getting after authentication is App Access Token. 身份验证后得到的是App Access令牌。
Quoting : 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
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 facebook docs . 来自facebook docs 。
What you need for your case is an user access token. 您需要的是用户访问令牌。 Refer this .
请参考此 。 A user needs to authenticate and grant access to your app for you have access to his friends list.
用户需要验证身份并授予对您应用的访问权限,因为您可以访问其朋友列表。
EDIT 编辑
For checking for a single user the url is https://graph.facebook.com/ {uid}?fields=installed&access_token=< ACCESS_TOKEN > 要检查单个用户,URL为https://graph.facebook.com/ {uid}?fields = installed&access_token = <ACCESS_TOKEN>
You are trying to get user friend list and then check if the app is installed. 您正在尝试获取用户朋友列表,然后检查是否已安装该应用程序。 I don't think getting user friend list is possible without user access token.
我认为没有用户访问令牌就不可能获得用户朋友列表。
EDIT 2 编辑2
Assuming from your comment that you have the list of frind's. 根据您的评论,假设您有frind的列表。 Then you need not call for each user instead you can use FQL.
然后,您无需为每个用户呼叫,而可以使用FQL。
https://graph.facebook.com/fql?q=SELECT uid,is_app_user from user where uid IN (uid1,uid2)
And if you have the user access token then you can directly do. 如果您拥有用户访问令牌,则可以直接进行操作。
https://graph.facebook.com/fql?q=SELECT uid,is_app_user from user where uid IN (SELECT uid2 FROM friend WHERE uid1 = me())
Hope this solves your problem. 希望这能解决您的问题。
Don't request / me / friends – because with an app access token the API won't know who „me” is supposed to be – request / userid / friends instead. 不要请求/ 我 / 朋友 -因为使用应用访问令牌,API不会知道“我”应该是谁-而是请求/ 用户ID / 朋友 。
Sorry, I was wrong before – the way to go is with an user access token , and just setting the request up against /me/friends… 抱歉,我以前做错了–方式是使用用户访问令牌 ,并根据/ me / friends设置请求…
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.