user1537407
user1537407

Reputation: 55

How to get Long-lived Access Token for App to Write on Facebook Page?

Digging around for several days to get my PHP app write on facebook fan page and got almost crazy.

  1. Already given my app manage_page permission for a particular facebook page.

  2. Visited

    h..s//www.facebook.com/dialog/oauth?client_id=APP_ID&redirect_uri=SOME_FALLBACK_URL_TO_GET_ACCESS_TOKEN_FROM_URL&response_type=token&scope=manage_pages,publish_stream
    
  3. Copied access token from result of previous step

  4. Visited

    h..s//graph.facebook.com/me/accounts?access_token=COPIED_ACCESS_TOKEN
    
  5. Got the result as following:

    "data": [
        {
             "name": "PAGE_TITLE",
             "access_token":     "SHORT_LIVING_ACCESS_TOKEN",
             "category": "Local/travel",
             "id": "PAGE_ID_THAT_APP_IS_TO_WRITE_ON_WALL",
             "perms": [
                        "ADMINISTER",
                        "EDIT_PROFILE",
                        "CREATE_CONTENT",
                        "MODERATE_CONTENT",
                        "CREATE_ADS",
                        "BASIC_ADMIN"
                      ]
       },
    
  6. Copied the SHORT_LIVING_ACCESS_TOKEN

  7. Visited

    h..s://graph.facebook.com/oauth/access_token?client_id={APP_ID}&client_secret={APP_SECRET}&grant_type=fb_exchange_token&fb_exchange_token={SHORT_LIVING_ACCESS_TOKEN_FROM_STEP_5}
    
  8. Getting the error and stuck here:

    {"error_code":1,"error_msg":"An unknown error occurred"}
    

p.s. I correctly replaced {APP_ID}, {APP_SECRET} where necessary.

Please, help!

Upvotes: 1

Views: 525

Answers (1)

C3roe
C3roe

Reputation: 96271

You’re doing it the wrong way around, I think. You are getting a short-lived page access token and try to prolong that.

What you should do, is get a short-lived user access token, prolong that, and then go get the page access token with the long-lived user access token.

That process should give you a page access token with no default expiry.

Upvotes: 2

Related Questions