我想从我的网站(我的网站的backOffice)上传我的脸书有趣页面中的一张图片+描述我没有找到一个明确的例子使用我尝试了很多脚本但我得到了很多错误我需要帮助这里是我的代码:
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
非常感谢
答案 0 :(得分:0)
如果您想按照自己想要的方式使用curl上传照片:
$photo_details['image'] = '@' . $file;
您需要提供路径,而不是网址。
答案 1 :(得分:0)
您似乎试图在请求中使用非本地图像。您需要在本地下载文件以在请求中发送它。
由于curl在本地寻找图像,因此将找不到文件“http://www.sudoku-gratuit.fr/illusion-optique/1image-illusion-optique18.jpg”。