Facebook PHP SDK: getting “long-lived” access token now that “offline_access” is deprecated

前端 未结 4 1251
灰色年华
灰色年华 2021-01-31 05:44

BASIC PROBLEM: I want my app to be able to make calls to the Facebook graph api about authorized users even while the user is away.

For example, I want

4条回答
  •  长情又很酷
    2021-01-31 06:17

    The selected answer is now outdated. Here are Facebook's instructions to swap a short-term token (provided in front-end) for a long-term token (server only):

    https://developers.facebook.com/docs/facebook-login/access-tokens/refreshing/

    Generate a Long-lived User or Page Access Token
    You will need the following:
    
    A valid User or Page Access Token
    Your App ID
    Your App Secret
    Query the GET oath/access_token endpoint.
    
    curl -i -X GET "https://graph.facebook.com/{graph-api-version}/oauth/access_token?  
        grant_type=fb_exchange_token           
        client_id={app-id}&
        client_secret={app-secret}&
        fb_exchange_token={your-access-token}" 
    
    Sample Response
    {
      "access_token":"{long-lived-access-token}",
      "token_type": "bearer",
      "expires_in": 5183944            //The number of seconds until the token expires
    }
    

提交回复
热议问题