【问题标题】:Uploading facebook event picture throws error上传 facebook 事件图片会引发错误
【发布时间】:2012-09-20 04:36:12
【问题描述】:

我正在尝试使用图片创建事件,但是当我将图片上传到 Facebook 时,它会抛出一个错误 (#324) 图片文件丢失或无效

这是上传图片的功能。

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;
} 

我在表单发布后使用的代码段

if ($file[$name]['error'] == 0) {
                                    $fileName = $file[$name]['name'];
                                    $fileInfo = pathinfo($fileName);
                                    $newFileName = md5($fileName . microtime()) . '.' . $fileInfo['extension'];
                                    $fullPath = $this->config->applications->uploadPath . $newFileName;
                                    $form->$name->addFilter('Rename', $fullPath);

                                    if ($form->$name->receive()) {
                                        $resize = new SimpleImage();
                                        $resize->load($fullPath);
                                        $resize->resizeToWidth($this->config->applications->resize->width);
                                        $resize->save($fullPath);
                                        // Gathering data for saving files information
                                        $fileInfo = array(
                                            'name' => $newFileName,
                                            'type' => FileTypes::IMAGE,
                                            'description' => 'Application: Uploaded from Events form in back-end',
                                        );

                                        $fileId = $dbFiles->save($fileInfo);

                                        $eventFileData = array(
                                            'event_id' => $eventId,
                                            'file_id' => $fileId,
                                            'main_image' => ($name == 'mainImage') ? 1 : 0
                                        );                                  
                                        $dbEventFiles->save($eventFileData);
                                        if ($name === 'mainImage') {
                                            $success = **$this->uploadFacebookEventPicture($fullPath, $eventData['fb_event_id']**);
                                        }
                                    }
                                }

facebook 对象是在上传文件为 true 的情况下创建的

 $facebook = new Facebook(array(
                'appId' => $config->facebook->appId,
                'secret' => $config->facebook->secret,
                'fileUpload' => true
            ));

【问题讨论】:

  • 你检查过uploadFacebookEventPicture里面的路径指向一个可读的图像文件吗?
  • 根据developers.facebook.com/docs/reference/api/event/#picture,参数必须命名为source(您现在使用的是picture),并且您必须针对/EVENT_ID/picture发布它——请试一试.
  • public function uploadFacebookEventPicture($fullPath, $eventId) { $imgData = array( 'picture' => '@' . realpath($fullPath) ); try { $data = $this->facebook->api('/'.$eventId . '/picture', 'post', $imgData); return $data; } catch (FacebookApiException $e) { error_log('Failed to attach picture to event. Exception: ' . $e->getMessage()); die($e->getMessage()); } return null; } 还没有解决问题,但是现在脚本没有捕捉到错误,但是仍然图片 - 没有出现,file_exists 和 is readable 都是真的,检查一下。
  • 没有帮助:(与上面的代码相同的行为
  • 看来这个问题的原因是facebook bug

标签: php facebook zend-framework


【解决方案1】:

根据 Facebook 错误跟踪器,此错误已得到修复: Bug tracker post

Status changed to Fixed

上面的代码适用于上传 facebook 事件图片。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-17
    • 2011-10-13
    • 2014-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-22
    • 1970-01-01
    相关资源
    最近更新 更多