views:

797

answers:

3

I have a couple of problems using facebook graph api.

1). When i try to upload a photo i get the following error "(#324) Requires upload file".

  $attachement = array(
                            'access_token'=> (...)',
                            'name' => 'uploaded foto',
                            'source' => 'C:\Documents and Settings\Username\Desktop\1.jpg'
                    );

        $fb_foto = $fb->api('me/photos','POST',$attachement);

I am sure that source is correct. I have tried with a photo from the internet and not from mu local PC also.

2). How can i delete an object from facebook?. (a wall message for example). I have tried this: $fb->api('/post_id','POST',array('method'=> 'delete'));

But i get "unsupported POST request" error.

Any help would be appreciated.

EDIT: Here is the complete solution i found for upload photos to Facebook. You need to have the version 2.1.1 or above of PHP SDK

 $fb = new Facebook(array(
                        'appId'  => ...,
                        'secret' => ...,
                        'cookie' => true,
        ));

$fb->setFileUploadSupport(true);
      $attachement = array(
                            'access_token'=> '...',
                            'name' => 'uploaded foto',
                            'source' => '@absolute_path_to_the_file'
                    );



      $fb_foto = $fb->api('me/photos','POST',$attachement);
+1  A: 

Concerning your 2nd problem, I remember reading somewhere about a DELETE request, instead of POST. See: http://developers.facebook.com/docs/api#deleting

Prot0
I knew i have seen it somewhere. Thanks
Popovich88
+1  A: 

Read the documentation

curl -F 'access_token=...' \
     -F '[email protected]' \
     -F 'message=Caption for the photo' \
     https://graph.facebook.com/me/photos

See how the source parameter is formatted?

$fb_foto = $fb->api('me/photos','POST',array(
    'access_token' => (...)
  , 'message'      => 'Caption'
  , 'source'       => '@' . realpath( 'path/to/file' )
));

To delete photos, again the documentation has your answer: Issue a DELETE request

$fb->api( '/PHOTO_ID', 'DELETE' );
Peter Bailey
I tried that but still get the same error. My only explanation is becuase i am working at localhost. Anywhay i dont have any other problems (posting to wall, post comments etc). $attachement = array( 'access_token'=> (...) 'name' => 'uploaded foto', 'source' => '@'. realpath('C:\Documents and Settings\Username\Desktop\1.jpg') ); $fb_foto = $fb->api('me/photos','POST',$attachement);
Popovich88
oh, most definitely because of localhost
Peter Bailey
No it wasn´t localhost. It was a bug with php SDK. I have updated to the 2.1.1 version and add this line: $fb->setFileUploadSupport(true);Now everything works fine.
Popovich88
A: 

I'm using this method with the new php-sdk (v2.1.1, facebook-php-sdk-v2.1.1-0-g08909f3.zip) to upload a photo for a new event. The php code below creates the event.

$fname="/tmp/foo.jpg";
$attachment =  array(
        'access_token' => $facebook->getAccessToken(),
        'name' => substr(event_name),
        'description' => my_description,
        'start_time' => my_start_time,
        'link' => my_link,
        'source'=> '@'.$fname
        );
$result = $facebook->api('/me/events', 'POST', $attachment);
kenberland