14

I have read this: trying to get app access token

And it doesn't work... I'm getting the following error:

"error": {
   "message": "An active access token must be used to query 
                          information about the current user.",
  "type": "OAuthException",
  "code": 2500
}

I need the app access token in order to create open graph objects that are owned by the application. I know how to create objects owned by the users, but I just cant find the correct way of creating the App access token.

AppId -> doesn't work... AppId|AppSecret -> doesn't work.... App ClientToken -> doesn't work....

Anyone know this?

Community
  • 1
  • 1
Roger Johansson
  • 22,764
  • 18
  • 97
  • 193
  • I know this is a really old question, but Roger, do you know where to add the app access Token in Android Studio ? [Check my question](http://stackoverflow.com/questions/43382064/how-to-get-accesstoken-for-graphrequest-newgraphpathrequest) I don't know where to add it... – Suhaib Apr 13 '17 at 08:25

3 Answers3

44

You can get it directly from the Access Token Tool.


Please note: For security, app access token should never be hard-coded into client-side code, doing so would give everyone who loaded your webpage or decompiled your app full access to your app secret, and therefore the ability to modify your app. This implies that most of the time, you will be using app access tokens only in server to server calls.

Sahil Mittal
  • 20,697
  • 12
  • 65
  • 90
  • +@sahil's answer is correct, but these days the above link shows only _user tokens_. To generate an _app token_ see [App Access Tokens](https://developers.facebook.com/docs/facebook-login/access-tokens/#apptokens) in the FB documentation. – johnsampson Dec 01 '17 at 06:45
  • 1
    @johnsampson, check again. The aforementioned link gives you both: *user access token* and *app access token* – Sahil Mittal Dec 04 '17 at 07:21
4

It looks like you have a valid token, you're just trying to query for the current user. If you're using the app token, however, there isn't a current user, so it's failing.

Gray
  • 2,333
  • 1
  • 19
  • 24
  • So is the problem that I'm posting to the wrong url? https://graph.facebook.com/me/objects/strongur:exercise?access_token=..accesstoken...&method=POST&object=...json... When passing the app token, should I not post to /me/objects/myapp ? – Roger Johansson Aug 04 '13 at 19:43
  • Found the problem, the url should be /app/objects when creating app hosted objects – Roger Johansson Aug 04 '13 at 20:11
0

If you are using Java language to fetch app access token, you can try this:

DefaultFacebookClient facebookClient = new DefaultFacebookClient(Version.LATEST);
AccessToken accessToken = facebookClient.obtainAppAccessToken(clientId, clientSecret);
System.out.println(accessToken);

To check whether it is valid, use access token debugger.

Rohan Pillai
  • 917
  • 3
  • 17
  • 26
Roshan
  • 1
  • 4