php – 通过Graph API安排的帖子经常不会发布
发布时间:2020-05-25 09:03:58 所属栏目:PHP 来源:互联网
导读:嗨,我正在使用facebook php sdk在我的粉丝页面发帖.我试图将这些帖子安排到未来.我遇到了一些问题.这是我的代码 ?php// This code is just a snippet of the example.php script// from the PHP-SDK https://github.com/facebook/facebook-php-sdk/blob/mas
|
嗨,我正在使用facebook php sdk在我的粉丝页面发帖.我试图将这些帖子安排到未来.我遇到了一些问题.这是我的代码 <?php
// This code is just a snippet of the example.php script
// from the PHP-SDK <https://github.com/facebook/facebook-php-sdk/blob/master/examples/example.php>
require_once('facebookphp/src/facebook.php');
$app_id = "xxxxx";
$app_secret = "xxxxxx";
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
'appId' => $app_id,'secret' => $app_secret,'fileUpload' => true,));
// Get User ID
$user = $facebook->getUser();
var_dump($user);
if ($user) {
try {
$page_id = 'xxxx';
$album_id = 'xxxxx';
$page_info = $facebook->api("/$page_id?fields=access_token");
if( !empty($page_info['access_token']) ) {
$args = array(
'access_token' => $page_info['access_token'],'scheduled_publish_time' => "1361642425",#an example timestamp
'message' => "test post",'source' => "@" . "/path/to/photo.jpg",'published' => "0",);
$post_id = $facebook->api("/$album_id/photos","post",$args);
#echo $post_id;
} else {
$permissions = $facebook->api("/me/permissions");
if( !array_key_exists('publish_stream',$permissions['data'][0]) ||
!array_key_exists('manage_pages',$permissions['data'][0])) {
// We don't have one of the permissions
// Alert the admin or ask for the permission!
header( "Location: " . $facebook->getLoginUrl(array("scope" => "publish_stream,manage_pages")) );
}
}
} catch (FacebookApiException $e) {
var_dump($e);
$user = null;
}
}
// Login or logout url will be needed depending on current user state.
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
echo '<a href="'.$logoutUrl.'">logout</a>';
} else {
$loginUrl = $facebook->getLoginUrl(array('scope'=>'manage_pages,publish_stream'));
echo '<a href="'.$loginUrl.'">login</a>';
}
// ... rest of your code
?>
此代码将照片发布到我未完美安排的Facebook页面,除非计划时间到期,照片未发布.在活动日志中,照片保留在“预定帖子”部分,错误为“抱歉,发布此预定帖子时出错” 我怀疑这是因为参数:’published’=> “0”, 如果我删除此参数或将其设置为1,则根本不会发布帖子,我收到错误“您无法在已发布的帖子上指定预定的发布时间” 使用上面的代码安排帖子,完美的工作我.我只是在11分钟后尝试并安排了这个帖子,我在11分钟后得到了通知,照片发布在所述专辑上.实际上它有点像facebook的bug. 只需转到每个帖子,点击“重新安排”并将时间调整15分钟(或者你想要的多少).出于某种原因,这会将它们单独重置,一切都恢复正常,帖子将再次根据时间表自行发布. 我知道这是修复Facebook应该自己修复的东西的一种单调乏味的方法,但它确实有效. (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
