我想上传一张图片+描述在我的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
Thanks to lot
如果您想以这种方式使用curl上传照片,在这一行:
$photo_details['image'] = '@' . $file;
你需要提供一个路径,而不是url
看起来您正在尝试使用不是本地的图像来发送请求。您需要在本地下载该文件,以便在请求中发送它。
由于curl在本地查找图像,因此无法找到文件"http://www.sudoku-gratuit.fr/illusion-optique/1image-illusion-optique18.jpg"。