Question

I am just learning restfb. I registered an app on the FB site and got an app ID and Secret keys. However, as per this tutorial, I am supposed to have an access token to initialize DefaultFacebookClient. I tried to follow the instructions there but none sufficiently explained how to get the access token out of the app ID and secret key.

Request https://graph.facebook.com/oauth/authorize?client_id=MY_API_KEY&redirect_uri=http://www.facebook.com/connect/login_success.html

Facebook will redirect you to http://www.facebook.com/connect/login_success.html?code=MY_VERIFICATION_CODE

Request https://graph.facebook.com/oauth/access_token?client_id=MY_API_KEY& redirect_uri=http://www.facebook.com/connect/login_success.html&client_secret=MY_APP_SECRET&code=MY_VERIFICATION_CODE

Facebook will respond with access_token=MY_ACCESS_TOKEN

I did exactly that but every time I get

{
   "error": {
      "message": "Error validating verification code. Please make sure your redirect_uri is identical to the one you used in the OAuth dialog request",
      "type": "OAuthException",
      "code": 100
   }
}

Any idea what I am supposed to do to get an access token and start using the API?

Était-ce utile?

La solution

It looks like the plugin authors assume that you will be authenticating a user with the Login Dialog or the JavaScript SDK.

Both of these methods return a user access token you can use. You need your App_ID and Secret to initialize these. Most Facebook operations require a user access token.

If you are making API calls solely to read public data, then you may be able to get away with an application access token. For this you can use the DefaultFacebookClient().obtainAppAccessToken() method of RestFB.

Autres conseils

I were having the same issue.

Adding a trailing slash to the redirect_uri-parameter solved the problem for me.

Also, make sure you are using the URI for your own app and not a facebook URI when making the requests.

E.g:

http://www.yoursite.com

didn't work for me while

http://www.yoursite.com/

did.

I am not sure if that's what you want, but anyway:

To get access token for users associated with an app, you can use the /accounts 'edge' (see here).

Also, this site about access tokens says that you can make calls to Graph API like that: https://graph.facebook.com/endpoint?access_token=app_id|app_secret

Now, to combine that, to get the access tokens (in JSON format along with some other stuff): https://graph.facebook.com/{your app id here}/accounts?access_token={again, your app id here}|{your app secret here}

Please substitute the fields in the url above and remove all the { and } from it.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top