Question

I wonder if someone can help me understand the difference between Access Tokens, App Access Tokens and when to use each.

My problem if that when I use the restFB libraries to obtain the access token:

AccessToken accessTokenT =
               new DefaultFacebookClient().obtainAppAccessToken(appID, appSecret);

As I would expect it returns the App Access token. However, when i use that token to instantiate the FacebookClient object:

FacebookClient facebookClient = new DefaultFacebookClient(accessToken);

It fails with the following message:

Exception in thread "main" com.restfb.exception.FacebookOAuthException: Received Facebook error response of type OAuthException: (#200) The user hasn't authorized the application to perform this action (code 200, subcode null)

If I go to the graph explorer and manually get an access token, then use that in my code, everything works fine.

I'm sure there's something subtle I'm missing and any help would be greatly appreciated.

Many thanks

Was it helpful?

Solution

Primarily there are 3 types of access tokens-

  1. User access token
  2. Page access token
  3. App access token

The documentation by facebook: Access Tokens, explains a lot about them. You can have a look.

You should initialize the facebookClient with the user access token. The user access token is obtained when a user login/authorizes the app. This token is used to query about the user(for what he has given permissions to the application). The App access token has very limited powers like: posting on behalf of the user once he has given app the authorization, or send the requests etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top