0

我已经制作了这个脚本。它工作完美,并将照片发布到我的 Facebook 粉丝专页。但是一小时后,登录令牌无效。如何永久登录我的 FB Fanpage。任何想法?

<?php
require_once('facebook.php');
$facebook = new Facebook(array(
    'appId'  => 'XXXXXXXXXXXXX',
    'secret' => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
    'fileUpload' => true
));
$access_token = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$facebook->setAccessToken($access_token);
$facebook->setExtendedAccessToken(); 
$params = array(
    'access_token' => $access_token
);
// The id of the fanpage
$fanpage = 'XXXXXXXXXXXXXX';
// Get the page access token
$accounts_list = $facebook->api('/me/accounts');
foreach($accounts_list['data'] as $account){
if($account['id'] == $fanpage){
    $fanpage_token = $account['access_token'];
    echo "<p>Page -- Access Token:<br>$fanpage_token</p>";
}
}
$args = array(
          'source' => '@'.realpath('img/17226_014.jpg'),
          'message' => 'php sdk test',
          'access_token' => $fanpage_token
         );
$post_url = '/'.$fb_page_id.'/photos';
$photo = $facebook->api($post_url, 'post', $args ); 
if( is_array( $photo ) && ! empty( $photo['id'] ) ) {
echo 'Photo uploaded. Check it on Graph API Explorer. ID: ' . $photo['id'];

} ?>

4

1 回答 1

1

您需要获取新的扩展访问令牌

<?php
    $new_access_token = $facebook->getAccessToken();
?>

在你调用 $facebook->setExtendedAccessToken();

当然,您需要使用该访问令牌进行下一次 API 调用。

于 2013-05-25T17:33:40.927 回答