douchun5976 2015-09-14 04:34
浏览 82
已采纳

获取Facebook Graph API扩展访问令牌

I can get the posts I need from a Facebook Page using this code in PHP:

$token = "ACCESS_TOKEN";
$data = file_get_contents("https://graph.facebook.com/PAGE_ID/feed?access_token=".$token);
$data = json_decode($data, true);

However, the access token it just last 1 hour. I saw that it's possible to request a long live token that lasts 60 days, but stills not so clear for me with a good example.

Do you guys know a good example using PHP? Thank you in advance!

  • 写回答

2条回答 默认 最新

  • doudou8783 2015-09-14 04:52
    关注

    As per the Facebook documentation, you need to pass the short-lived access-token with app secret and in return you will get the Long-lived access-token

    To get the long-lived user access_token simply pass your own client_id (your app_id), your app_secret, and the non-expired, short-lived access_token to the endpoint below. You will be returned a new long-lived user access_token; this access_token will exist in addition to the short-lived access_token that was passed into the endpoint.

    Code Sample

    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 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?