facebook: permanent Page Access Token?

后端 未结 16 2175
情书的邮戳
情书的邮戳 2020-11-22 02:39

I work on a project that has facebook pages as one of its data sources. It imports some data from it periodically with no GUI involved. Then we use a web app to show the dat

16条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 03:12

    I made a PHP script to make it easier. Create an app. In the Graph API Explorer select your App and get a user token with manage_pages and publish_pages permission. Find your page's ID at the bottom of its About page. Fill in the config vars and run the script.

    '',
        'appid'=>'',
        'appsecret'=>'',
        'pageid'=>''
    ];
    
    echo generate_token($args);
    
    function generate_token($args){
        $r=json_decode(file_get_contents("https://graph.facebook.com/v2.8/oauth/access_token?grant_type=fb_exchange_token&client_id={$args['appid']}&client_secret={$args['appsecret']}&fb_exchange_token={$args['usertoken']}")); // get long-lived token
        $longtoken=$r->access_token;
        $r=json_decode(file_get_contents("https://graph.facebook.com/v2.8/me?access_token={$longtoken}")); // get user id
        $userid=$r->id;
        $r=json_decode(file_get_contents("https://graph.facebook.com/v2.8/{$userid}/accounts?access_token={$longtoken}")); // get permanent token
        foreach($r->data as $d) if($d->id==$args['pageid']) return $d->access_token;
    }
    

提交回复
热议问题