PHP上传Facebook照片


PHP to upload Facebook Photos

我试图使用Facebook Graph API将照片上传到Facebook Fan页面,我能够上传照片,但它被上传为一个小缩略图,旁边写着我的主机名两次(即www.myhost.comwww.myhost.com)

我需要上传原图,照片旁边不能有任何文字

我用:

$params = array(
   "access_token" => $access_token,
   "picture" => "http://www.myhost.com/fb/Azkar-001.png",
);
$ret = $fb->api('/myID/feed', 'POST', $params);

感谢您的反馈,因为我是图形API的新手

一个常见的错误是使用me/feed, me/feed目标和发布状态更新&链接文章到用户的流

上传照片到用户流/时间轴使用me/photos

$ret = $fb->api('/me/photos', 'POST', $params);

等等,您还有另一个问题,即使用参数picture,为什么?因为你是从一个URL上传的,用url代替picture

$params = array(
   "access_token" => $access_token,
   "url" => "http://www.myhost.com/fb/Azkar-001.png",
);
$ret = $fb->api('/me/photos', 'POST', $params);

感谢Adam, HYG完整代码:

<?php
require_once("facebook.php");
$access_token = "Add_Your_Access_Token_here";
$facebook = new Facebook(array(
   'appId'  => 'Add_Your_App_ID_Here',
   'secret' => 'Add_Your_App_Secret_Here',
   'fileUpload' => true, // I put this as False in my original program and this was the reason for my early issues
   'cookie' => true // enable optional cookie support
));
$facebook->setFileUploadSupport(true);
$file = "@".realpath("001.png"); //Put the file path here
$args = array(
   "message" => "Photo Caption'"
   "access_token" => $access_token,
   "image" => $file
);
$data = $facebook->api('/me/photos', 'post', $args); //This is the line that made everything working fine, thanks to Adam
if ($data) print_r("success");
?>