La carga de la imagen del evento de Facebook arroja un error

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

this is the function to upload picture.

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

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

preguntado el 28 de agosto de 12 a las 08:08

Have you checked inside of uploadFacebookEventPicture that the path points to a readable image file? -

Según developers.facebook.com/docs/reference/api/event/#picture the parameter has to be named source (you’re using picture right now) and you have to post it against /EVENT_ID/picture – give that a try, please. -

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; } haven't solved the problem, but now script doesn't catch error, but still picture - doesn't appear, file_exists and is readable are true, checked that. -

doesn't help :( same behavior as with the code above -

It seems that the cause of this issue is error de facebook . -

1 Respuestas

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

Status changed to Fixed

Code above works fine for uploading facebook event picture.

Respondido el 19 de Septiembre de 12 a las 21:09

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.