上传Facebook的事件图片抛出错误(Uploading facebook event pictu

2019-06-27 11:54发布

我试图创建一个图片的事件,但是当我上传图片至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的对象与上传文件真正创建

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

Answer 1:

根据Facebook的bug跟踪系统,这个bug已经修复: 错误跟踪后

Status changed to Fixed

上面的代码工作正常上传Facebook的事件图片。



文章来源: Uploading facebook event picture throws error