上载Facebook事件图片会引发错误

上载Facebook事件图片会引发错误

本文介绍了上载Facebook事件图片会引发错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to create event with picture, but when i upload picture to facebook it throws me an error (#324) Missing or invalid image file

这是上传图片的功能.

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

表格发布后我使用的代码段

the par of code i use after form post

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 object is created with upload file true

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

推荐答案

根据Facebook错误跟踪器,此错误已得到修复:错误跟踪器帖子

According to Facebook bug tracker, this bug has been fixed:Bug tracker post

Status changed to Fixed

上面的代码可用于上传Facebook活动图片.

Code above works fine for uploading facebook event picture.

这篇关于上载Facebook事件图片会引发错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 19:42