用于Facebook的PHP SDK:上传使用Graph API创建的事件的图像

时间:2012-08-29 03:34:29

标签: php facebook cakephp facebook-graph-api

有人可以解释我的问题吗?

<?php

$config = array();
$config['appId'] =  "foo";
$config['secret'] = "bar";
$config['cookie'] = true;
$config['fileUpload'] = true;

$facebook = new Facebook($config);

$eventParams = array(
    "privacy_type"  => $this->request->data['Event']['privacy'],
    "name"          => $this->request->data['Event']['event'],
    "description"   => $this->request->data['Event']['details'],
    "start_time"    => $this->request->data['Event']['when'],
    "country"       => "NZ"
);

//around 300x300 pixels
//I have set the permissions to Everyone
$imgpath = "C:\\Yes\\Windows\\Path\\Photo_for_the_event_app.jpg"; 
$eventParams["@file.jpg"] = "@".$imgpath;

$fbEvent = $facebook->api("me/events", "POST", $eventParams);

var_dump($fbEvent); //I get the event id

当要求用户允许应用以他的身份发布时,我的“范围”中也有此内容:user_about_me,email,publish_stream,create_event,photo_upload

这很有效。它使用我指定的所有细节创建事件。除了事件图像。

我去过大多数与我的问题相关的Stackoverflow帖子,但所有帖子都不适合我。 (EG:https://stackoverflow.com/a/4245260/66767

我也没有任何错误。

有什么想法吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

是的,这个想法是Facebook有bug。 我也有事件图片的问题。 The topic in tracker这是我在stackOverflow上的post

顺便说一句,您可以在创建活动后尝试此代码 - &gt;

public function uploadFacebookEventPicture($fullPath, $eventId) {
    $mainImage = '@' . $fullPath;   
    $imgData = array(
        'picture' => $mainImage
    );
    try {
        $data = $this->facebook->api('/'.$eventId, 'post', $imgData);
        return $data;
    } catch (FacebookApiException $e) {
        error_log('Failed to attach picture to event. Exception: ' . $e->getMessage());
    }       
    return null;
} 

也许这对你有用,对我来说,自从Facebook问题被发现后它就停止工作了。