我想从我的网站(网站的backOffice)上传一张图片+描述在我的facebook有趣的页面上,我没有找到一个明确的例子来使用,我尝试了很多脚本,但我得到了很多错误,我需要帮助,这里是我的代码:
function postOnFacebook($app_id, $app_secret, $message, $icon) {
require 'src/base_facebook.php';
require 'src/facebook.php';
$curlcontent = "curl";
$curlstatus = "Curl is not installed - This is a Problem";
if (function_exists('curl_init')) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.facebook.com/restserver.php');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0');
$curlcontent = curl_exec($ch);
curl_close($ch);
$curlstatus = "Curl is available but cannot access Facebook - This is a problem ";
if (strlen($curlcontent) > 6) {
$curlstatus = "Curl is available and can access Facebook - All is OK";
}
}
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'fileUpload' => true,
));
$facebook->setFileUploadSupport(true);
$photo_details = array(
'message' => 'Photo message',
'access_token' => $facebook->getAccessToken()
);
$file = $icon; //Example image file
$photo_details['image'] = '@' . realpath($file);
$upload_photo = $facebook->api('/me/photos', 'post', $photo_details);但是我得到了这个错误:
Fatal error: Uncaught OAuthException: An active access token must be used to query information about the current user. thrown in C:\xampp\htdocs\facebookSender\src\base_facebook.php on line 1039非常感谢
发布于 2011-12-20 23:27:24
如果你想以这种方式使用curl上传照片,在下面的代码行上:
$photo_details['image'] = '@' . $file;您需要提供路径,而不是url。
发布于 2011-12-20 23:27:50
看起来您正在尝试使用非本地图像发送您的请求。您需要在本地下载该文件,才能在请求中发送它。
由于curl正在本地查找图像,因此将找不到文件"http://www.sudoku-gratuit.fr/illusion-optique/1image-illusion-optique18.jpg“。
https://stackoverflow.com/questions/8577693
复制相似问题