在functions.php(wordpress)中发布\u future\u帖子不要运行使用Facebook SDK 3制作的脚本
亲爱的Wordpress黑客和爱好者们: 每次使用FacebookSDK3发布预定帖子时,我的脚本都会自动将照片发布到粉丝页面,这让我很恼火 问题是,当wp\u cron在functions.php中执行一行时,脚本停止运行,该行在使用添加操作“publish\u future\u post”,“future\u post\u being\u published”,10,1;发布时必须填充对象Facebook;。用publish_post可以完美地工作 遇到以下情况时,脚本将停止运行:在functions.php(wordpress)中发布\u future\u帖子不要运行使用Facebook SDK 3制作的脚本,facebook,wordpress,cron,schedule,Facebook,Wordpress,Cron,Schedule,亲爱的Wordpress黑客和爱好者们: 每次使用FacebookSDK3发布预定帖子时,我的脚本都会自动将照片发布到粉丝页面,这让我很恼火 问题是,当wp\u cron在functions.php中执行一行时,脚本停止运行,该行在使用添加操作“publish\u future\u post”,“future\u post\u being\u published”,10,1;发布时必须填充对象Facebook;。用publish_post可以完美地工作 遇到以下情况时,脚本将停止运行: $fac
$facebook = new Facebook(array(
'appId' => '1xxxxxx1',
'secret' => '28xxxxxxd91',
'fileUpload' => true
));
直接从后台发布帖子时不会出现此问题,事实上,函数add_action'publish_post'、'future_post_being_published',10,1;工作完美
我可以说它停止了,因为我添加了一些调试行,在代码的各个部分向我发送电子邮件,但我只有在发布帖子被激活时才能获得所有这些内容,而不是在将来发布帖子时
下面是脚本:
function future_post_being_published($post_id)
{
$post = get_post($post_id);
wp_mail( 'test@test.com', 'TEST1', 'TEST1' );
error_reporting(E_ALL);
ini_set('display_errors', '1');
include '../../../script/facebook-php-sdk-master/src/facebook.php';
wp_mail( 'test@test.com', 'TEST2', 'TEST2' );
$facebook = new Facebook(array(
'appId' => '1xxxx1',
'secret' => '2xxxx1',
'fileUpload' => true
));
wp_mail( 'test@test.com', 'TEST3', 'TEST3' );
#It can be found at https://developers.facebook.com/tools/access_token/
#Change to your token.
$access_token = 'CxxxxxxxxxD';
$params = array('access_token' => $access_token);
#The id of the fanpage
$fanpage = '3xxxxxxx9';
#The id of the album
$album_id ='4xxxxxxx37';
wp_mail( 'test@test.com', 'TEST4', 'TEST4' );
$accounts = $facebook->api('/INSERT_USER_FACEBOOK/accounts', 'GET', $params);
wp_mail( 'test@test.com', 'TEST5', 'TEST5' );
foreach($accounts['data'] as $account) {
if( $account['id'] == $fanpage || $account['name'] == $fanpage ){
$fanpage_token = $account['access_token'];
}
}
wp_mail( 'test@test.com', 'TEST6', 'TEST6' );
$img = "http://www.test.com/test.jpg";
$titolo ="Title!";
$ret_obj = $facebook->api('/me/photos', 'POST', array(
'url' => $img,
'message' => $titolo . ' | Test !!!',
'no_story' => 0,
'access_token' => $fanpage_token,
'aid' => $album_id
));
wp_mail( 'test@test.com', 'TEST7', 'TEST7' );
}
add_action('publish_future_post', 'future_post_being_published', 10, 1);
add_action('publish_post', 'future_post_being_published', 10, 1);
因此,简单地说:
当它被调用publish_post时,图像会被发布在facebook的页面墙上,我会收到所有的电子邮件TEST1、TEST2、…、TEST7
当它调用publish_future_post时,图像没有发布,我只收到电子邮件TEST1和TEST2。
我的问题是:为什么脚本在调用publish\u future\u post时不发布图像?可能它无法将值分配给对象facebook?如何修复它
非常感谢您的关注和宝贵的帮助!
最好的
Simone很可能您只是遇到了未捕获的异常,因为您的用户访问令牌已过期…嗨,CBroe,不,访问令牌未过期。正如我所说,当我马上发布时,它工作得很好,而当我安排发布时,它就不工作了,所以可能是CRON无法创建对象$facebook=newfacebook。这是可能的,我现在不知道。