我已经制作了这个脚本。它工作完美,并将照片发布到我的 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'];
} ?>