Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook access_token: how do I get it once the user accepted my app?

When a user visits my site which contains a facebook app the first time, it requires him to allow it and he gets promted to do that, then I get the code which I can convert to an access_token. So far so good.

But how do I get the token once the user has already visited the site? As long as this token form the first time is active everything is fine. But how do I get another token when the user had already allowed the app a week ago and is only visiting my page again?

like image 631
hoktar Avatar asked Apr 30 '10 09:04

hoktar


People also ask

How do I get app access token?

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.

How do I get a short live access token on Facebook?

Go to https://developers.facebook.com/tools/explorer/ and select your app from the first drop down menu, in the left. Click on the button "Get access token", and in the "Select Permissions" window, click in "Extended Permissions" and check manage_pages and publish_stream, and click in "Get Access Token" blue button.

How long do Facebook access tokens last?

When your app uses Facebook Login to authenticate someone, it receives a User access token. If your app uses one of the Facebook SDKs, this token lasts for about 60 days. However, the SDKs automatically refresh the token whenever the person uses your app, so the tokens expire 60 days after last use.


1 Answers

Now that Facebook is migrating to Oauth2, the cookie created by the Javascript is different. I got it to work for me and added it to a fork of the FGraph plugin for Rails - https://github.com/imme5150/fgraph

One of the tricks is that when you request the access_token from the "code" parameter stored in the cookie, you have to pass in "redirect_uri", but you want it to be blank.

like image 140
Josh Avatar answered Sep 23 '22 15:09

Josh