Blog

5 Apr

How to create a Facebook Access Token?

We get lots of questions about the Facebook Access Token. If you have problems to create an access token, maybe these tools helps you:

Graph API Explorer

With the Graph API Explorer you can create your own access token.

  • You can choose an app from the dropdown menu (right, top)
  • You can choose which permissions should be included (Button: Get Access Token)
  • You can chosse a connection (feed, posts, …)

https://developers.facebook.com/tools/explorer/

Debugger

If you have created an access token you can use the debugger to get informations about:

  • App ID
  • User ID
  • Issued
  • Expires
  • Valid
  • Origin
  • Scopes

https://developers.facebook.com/tools/debug

14 responses to “How to create a Facebook Access Token?”

  1. Jehuty
    10. May 2012 07:30:20

    Hi there,

    Thank you for sharing. I’ve tried with your solution by obtaining an access token from https://developers.facebook.com/tools/explorer/
    As i was trying to create an access token for “A Page” instead of an app. I selected Graph API Explorer and generate an access token for that purpose. I’ve used the access token tested with you script it works fine, but once i logout my facebook account it expired. I’ve also tried with APP and it expired right after i logout my facebook as well.

    Would you mind if i ask how can i get a non-expired access token? I’ve tried look through stackoverflow and done some research but no luck on finding positive solution yet.

    Thank You

  2. Jehuty
    11. May 2012 00:09:05

    Hi neosmart,

    Thank you for your reply.

    I’ve read through your guide and facebook’s developers page. From the linked that you given above i’ve check the offline_access extention, publish_stream, manage_page and generate a tokens from there. But it still doesn’t work once i logout my facebook. By any chance you know why and any tips on how to generate a 60days code?

    Thank you

  3. Dario
    16. Jun 2012 07:17:07

    For 60 day expiring codes:

    1. Go to http://developers.facebook.com/apps
    2. Create a new app (website login app)
    3. Add your domain name (where you want the neosmart thingy to display) into site domain and the ticked FB login thingy
    4. Copy the app id
    5. Change the following url so that the app id is you apps id and the redirect website is the website from earlier

    https://graph.facebook.com/oauth/authorize?type=user_agent&client_id=123456789123456&redirect_uri=http%3A%2F%2Fwww.example.com&scope=read_stream,manage_pages,offline_access,user_photos

    The above “scope” is for a page feed, for personal feeds, use something like: read_stream,user_photos,user_status,friends_photos,offline_access

    6. Save the url in a text file for future use. Go to the URL, authenticate.
    7. Copy the URL that you are redirected to & paste it in some text file so you can see the whole thing
    8. The jumble of letters between access_token= and &expires_in= is the access token

    9. in 59 days (expires in 60), open that text file that I told you to save, repeat from step 7 onwards.

    I’m sure that there’s a better way, but this is what I’ve been using for a few years now and it’s always worked (yep, before they didn’t expire after 60 days)

  4. 14. Aug 2012 17:52:27

    To be sure I understand correctly, we are required to log in and update the access token every 60 days in order to keep the Facebook stream displaying on our website?

  5. 02. Oct 2012 21:17:59

    Fortunately, if you are trying to get the stream of a Facebook Page, there IS a better way. And one to get access tokens that never expire for pages.

    Note: You need to A) be logged into FB, and B) be an admin for the page for which you are trying to get the stream.

    1. Create an app on FB for your website. After creating it, make sure toe add your domain to App Domains and check Website with Facebook Login underneath “Select how your app integrates w FB” and provide your Site URL (which will be the oauth redirect_uri).

    2. Visit the following to generate a new SHORT-LIVED (1 hour) access token:

    https://www.facebook.com?
    client_id=[APPID]&
    client_secret=[APPSECRET]&
    redirect_uri=[http://APPURL]&
    scope=manage_pages,read_stream&
    response_type=token

    3. Take that short-lived access token and send it here:

    https://graph.facebook.com/oauth/access_token?
    client_id=APP_ID&
    client_secret=APP_SECRET&
    grant_type=fb_exchange_token&
    fb_exchange_token=EXISTING_ACCESS_TOKEN

    4. Then, either in FB’s Graph API Explorer or on your own, visit here:

    https://graph.facebook.com/me/accounts

    This last step will include all of the pages for which you are an admin along with their AppIDs and Access Tokens. These tokens will not expire (you can verify using the Debug button in FB’s Graph API Explorer)

    BOOM! YMMV.

    1. 02. Oct 2012 21:21:11

      NOTE: In the steps above, you need to use the access token from step 3 (which is now a LONG-LIVED, 60 day token) in step 4 in order to get the non-expiring access tokens for your page.

  6. zul
    03. Oct 2012 05:53:45

    how to get access token? i dont understand :(

  7. 20. Dec 2012 07:59:48

    Please note the complete steps

    1. Create an application in facebook with your website url
    3. Run this link in your Browser.

    2. Visit the following to generate a new SHORT-LIVED (1 hour) access token:

    https://www.facebook.com?
    client_id=[APPID]&
    client_secret=[APPSECRET]&
    redirect_uri=[http://APPURL]&
    scope=manage_pages,read_stream&
    response_type=token

    3. Take that short-lived access token and send it here:

    https://graph.facebook.com/oauth/access_token?
    client_id=APP_ID&
    client_secret=APP_SECRET&
    grant_type=fb_exchange_token&
    fb_exchange_token=EXISTING_ACCESS_TOKEN

    4. Then, either in FB’s Graph API Explorer or on your own, visit here:

    https://graph.facebook.com/me/accounts?access_token=~TOKEN~

    then paste the token and id in the code ,then you will get the result

  8. danielronnstam
    21. Jan 2013 14:37:13

    were do I find the app url in step 2 ?

  9. danielronnstam
    21. Jan 2013 14:41:23

    I used my own url in the APPURL in the link code, but I get no access token, only facebook.

    Can someone please write a tutorial for nutcases ? I’m not a coder. Step by step explain in detail ?

  10. danielronnstam
    23. Jan 2013 16:44:39

    step 4 doesn’t work !!!!!