脚本宝典收集整理的这篇文章主要介绍了php – Facebook图片api照片上传到粉丝页面相册,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
<?PHP include_once 'faceBook-PHP-sdk/src/facebook.PHP'; include_once 'config.PHP';//this file contains the secret key and app id etc... $facebook = new Facebook(array( 'appId' => FACEBOOK_APP_ID,'secret' => FACEBOOK_SECRET_KEY,'cookie' => true,'domain' => 'your callback url goes here' )); $session = $facebook->getSession(); if (!$session) { $url = $facebook->getLoginUrl(array( 'canvas' => 1,'fbconnect' => 0,'req_PErms'=>'user_photos,publish_stream,offline_access'//here I am requesting the required permissions,IT should work with publish_stream alone,but I added the others just to be safe )); echo 'You are not LOGged in,please <a href="' . $facebook->getLoginUrl() . '">Login</a> to access this application'; } else{ try { $uid = $facebook->getUser(); $me = $facebook->api('/me'); $token = $session['access_token'];//here I get the token From the $session array $album_id = 'the id of the album you wish to upload to eg: 1122'; //upload your photo $file= 'test.jpg'; $args = array( 'message' => 'Photo from application',); $args[basename($file)] = '@' . realpath($file); $ch = curl_init(); $url = 'https://graph.facebook.COM/'.$album_id.'/photos?access_token='.$token; curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_HEADER,false); curl_setopt($ch,CURLOPT_RETURNtransfer,true); curl_setopt($ch,CURLOPT_POST,CURLOPT_POSTFIELDS,$args); $data = curl_exec($ch); //returns the id of the photo you just uploaded PRint_r(json_decode($data,true)); } catch(FacebookApiException $e){ echo "Error:" . print_r($e,true); } } ?>
我希望这会有所帮助,我和朋友在墙上砸了很长时间才能让这个工作变得有效!
无论如何,这是我的问题,如何将图像上传到粉丝页面?我正在努力让这个工作,当我上传图像我得到的是照片ID但没有照片在相册中.
以上是脚本宝典为你收集整理的php – Facebook图片api照片上传到粉丝页面相册全部内容,希望文章能够帮你解决php – Facebook图片api照片上传到粉丝页面相册所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。