Facebook cron 作业将每日照片上传给多个用户
我开发了一个小型faceinhole类型的应用程序,将每日照片上传到相册,并每天将倒计时粘贴在图片中,直到活动当天。 我试图实现每日上传并发布到保存的每个用户的墙上,但似乎每次都失败..应用程序请求离线访问和发布流..它保存 access_token 和用户 ID。当 cron 作业每天运行时,它会成功上传 1 或 2 次,然后出现错误 505 page not found。这是我的代码。关于如何改变它以使其发挥作用有什么想法吗?
$app_id = "XXXXXXXXXXXXXXXXXXXX";
$app_secret = "XXXXXXXXXXXXXXXXXXXXXXXXX";
$sel=mysql_query("SELECT * FROM faceinhole WHERE imagen!='' AND activo=1");
while($as=mysql_fetch_array($sel)){
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true,
'domain' => "mydomain.com"
));
extract($as);
if(is_file($imagen)){
$future=mktime(20,0,0,10,14,2011);
$now = time();
$timeleft = $future-$now;
$daysleft=floor($timeleft/60/60/24);
list($w,$h)=getimagesize($imagen);
$imagen2=imagecreatefromjpeg($imagen);
imagepng($imagen2,$imagen.".png");
$imagen3=imagecreatefrompng($imagen.".png");
$color = imagecolorallocate($imagen3, 58, 221, 2);
imagettftext ( $imagen3 , 64 , 0 , 124 ,315 , $color , "Gotham-Ultra.ttf" , "$daysleft" );
$prefijo2 = substr(md5(uniqid(rand())),0,6);
$connum="fotos/".$prefijo."_feis_num.png";
imagepng($imagen3,$connum);
$facebook->setFileUploadSupport(true);
if($album_id!=""){
$album_uid=$album_id;
}else{
$album_details = array(
'access_token' => "$access_token",
'message'=> "Mis camisetas de los Juegos Panamericanos Guadalajara 2011. Viste la camiseta Panamericana para tu perfil de facebook aquí -> http://facebook.com/galeriasgdl?sk=app_$app_id",
'name'=> 'Mis camisetas Panamericanas'
);
try{
$create_album = $facebook->api('/me/albums', 'post', $album_details);
}catch(Exeption $e){
}
$album_uid = $create_album['id'];
mysql_query("UPDATE faceinhole SET album_id='$album_uid' WHERE user_id='$user_id'")or die(mysql_error());;
}
$photo_details = array(
'access_token' => "$access_token",
'message'=> "Estoy a $daysleft días de los Juegos Panamericanos Guadalajara 2011. Viste la camiseta Panamericana para tu perfil de facebook aquí -> http://facebook.com/galeriasgdl?sk=app_$app_id"
);
$file=$connum;
$photo_details['image'] = '@' . realpath($file);
try{$upload_photo = $facebook->api('/'.$album_uid.'/photos', 'post', $photo_details);}catch(Exeption $e){}
}
}
I've developed a small faceinhole type app and where a daily photo is uploaded to an album with a count down pasted in the picture everyday until the day of the event.
Im trying to acheive daily upload and post to wall of every user ive saved but it seems to fail everytime.. the app request for offline access and publish stream.. its saves access_token and user id. When cron job runs everyday it gets 1 or 2 successfull uploads and then it gets error 505 page not found. Heres my code. Any ideas on how to change this in order it to work?
$app_id = "XXXXXXXXXXXXXXXXXXXX";
$app_secret = "XXXXXXXXXXXXXXXXXXXXXXXXX";
$sel=mysql_query("SELECT * FROM faceinhole WHERE imagen!='' AND activo=1");
while($as=mysql_fetch_array($sel)){
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true,
'domain' => "mydomain.com"
));
extract($as);
if(is_file($imagen)){
$future=mktime(20,0,0,10,14,2011);
$now = time();
$timeleft = $future-$now;
$daysleft=floor($timeleft/60/60/24);
list($w,$h)=getimagesize($imagen);
$imagen2=imagecreatefromjpeg($imagen);
imagepng($imagen2,$imagen.".png");
$imagen3=imagecreatefrompng($imagen.".png");
$color = imagecolorallocate($imagen3, 58, 221, 2);
imagettftext ( $imagen3 , 64 , 0 , 124 ,315 , $color , "Gotham-Ultra.ttf" , "$daysleft" );
$prefijo2 = substr(md5(uniqid(rand())),0,6);
$connum="fotos/".$prefijo."_feis_num.png";
imagepng($imagen3,$connum);
$facebook->setFileUploadSupport(true);
if($album_id!=""){
$album_uid=$album_id;
}else{
$album_details = array(
'access_token' => "$access_token",
'message'=> "Mis camisetas de los Juegos Panamericanos Guadalajara 2011. Viste la camiseta Panamericana para tu perfil de facebook aquí -> http://facebook.com/galeriasgdl?sk=app_$app_id",
'name'=> 'Mis camisetas Panamericanas'
);
try{
$create_album = $facebook->api('/me/albums', 'post', $album_details);
}catch(Exeption $e){
}
$album_uid = $create_album['id'];
mysql_query("UPDATE faceinhole SET album_id='$album_uid' WHERE user_id='$user_id'")or die(mysql_error());;
}
$photo_details = array(
'access_token' => "$access_token",
'message'=> "Estoy a $daysleft días de los Juegos Panamericanos Guadalajara 2011. Viste la camiseta Panamericana para tu perfil de facebook aquí -> http://facebook.com/galeriasgdl?sk=app_$app_id"
);
$file=$connum;
$photo_details['image'] = '@' . realpath($file);
try{$upload_photo = $facebook->api('/'.$album_uid.'/photos', 'post', $photo_details);}catch(Exeption $e){}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
即使获得同意,自动发布也会受到政策团队的反对。
Automatic posting, even with consent, is frowned upon by the Policy Team.