使用图形api php创建面部事件时上传图像

时间:2014-03-11 17:50:25

标签: php facebook

我似乎无法让这个工作。事件加载正常,但图像只是没有上传,请让我知道我做错了什么,我认为图片网址格式存在问题,是否需要@在前面?,我已经尝试了没有它并没有#39; t work:

////////////////////////////////////////////////////////////////////////////////////////
require 'facebook.php';
// appId and secret all work fine
$facebook = new Facebook(array(
    'appId'  => '************',
    'secret' => '**************',
    'fileUpload' => true
));

// Get User ID
$user = $facebook->getUser();

if ($user) {
    try {
        $user_profile = $facebook->api('/me');
        $response = $facebook->api(
            "/me/events",
            "POST",
            array (
                'name' => $title,
                'start_time' => $start_time,
                'location' => $location,
                'end_time' => $end_time,
                'description' => $description,
                'picture' => '@http://andyotto.files.wordpress.com/2013/01/donald-    duck.gif?w=863',                
                'venue' => $venue
            )
        );
        if (count($response)>0){
            $response_message = "Event successfully added uploaded to Facebook.";
        }else{
            $response_message = "There was a problem uploading your event to Facebook.";
        }
    } catch (FacebookApiException $e) {
        error_log($e);
        $user = null;
    }
}


if ($user) {
    $logoutUrl = $facebook->getLogoutUrl();
} else {
    $statusUrl = $facebook->getLoginStatusUrl();
    $loginUrl = $facebook->getLoginUrl(array(
        'scope'=>'create_event'
    ));
    header( 'Location:'.$loginUrl ) ; 
 }  

1 个答案:

答案 0 :(得分:0)

从文档中可以看出,一旦发布了事件(https://developers.facebook.com/docs/graph-api/reference/user/events/#publish),就无法直接上传图片,至少没有描述图片。

根据此文档(https://developers.facebook.com/docs/graph-api/reference/event#picture),您可以通过

创建事件的图片
POST /{EVENT_ID}/picture

将图片编码为" multipart / form-data"在请求的正文参数" source"。