tags:

views:

1017

answers:

4

I would like to know how to add a picture to an event using the Facebook Graph API. I have seen this question and tried some variations on that theme, without any success. The official documentation doesn't seem to make any mention of it.

I'm using PHP for this particular project and I've looked at the PHP SDK source code, which is not helpful in any way. Requesting metadata for pictures using https://graph.facebook.com/eventid/picture?metadata=1&access_token... doesn't seem to be recognized, so no help there either.

Has anyone come across some example or documentation on how to do this? (don't care about which language it is in)

+2  A: 

Hey,

While searching for the problem, i found following links which might be of interest.

http://wiki.developers.facebook.com/index.php/PHP

http://wiki.developers.facebook.com/index.php/Photos.upload

http://developers.facebook.com/docs/reference/rest/

In last link, check "Publishing methods" and "Dashboard API methods". It has methods for Video and Photo uploading.

Photo: http://developers.facebook.com/docs/reference/rest/photos.upload

Video: http://developers.facebook.com/docs/reference/rest/video.upload

--------------EDIT---21st May,2010,8:58 PM IST---------------------

Check this thread out, it shows photo uploding code in PHP using graph API which you mentioned.

http://stackoverflow.com/questions/2718610/upload-photo-to-album/2728275#2728275

I hope this helps.

thanks.

Paarth
I have seen those pages, but they aren't about the Graph API. While the old API will be supported for some time to come, I'm writing my web app to last for a while without maintenance. As such, I would like to use the current API. I already use the Graph API for a number of other tasks, and mixing different APIs would make things rather messy.
Thorarin
Check the link i added in the edit.Also check this new lightweight java facebook API. May be you can find some reference from it.**http://restfb.com/**thanks.
Paarth
A: 

It appears to be something that is not yet supported by the Graph API. It is not mentioned in the official documentation, and attempts Graph-ify old style API calls do not appear to work.

There has been some discussion on what various people have tried on this forum: http://forum.developers.facebook.com/viewtopic.php?id=56717

For now, it seems the only option is to use the old API (official documentation). Paarth's answer provides some additional useful links to get started with that. However, since my question was specifically about the Graph API, the answer (for now) is: it cannot be done.

I'll update this answer as support for event picture uploading is added to the Graph API.

Thorarin
A: 

I had the same problem, this code work for me:

// create the event
// ...

// upload the picture
$file = "pathtothefile";
$args[basename($file)] = '@' . realpath($file);
$data = $facebook->api('/'. $event_id, 'post', $args);

But sometimes I get "(#324) Missing or invalid image file" error

Sidhannowe
A: 

This is supported by the Graph API, however it is poorly documented. You need to send the image as multipart attachment in the POST request. Try this:

curl -F 'access_token=...' \
-F 'name=Test Event' \
-F 'description=The description' \
-F 'start_time=2012-09-01T12:00:00+0000' \
-F '@file.jpg=@/path/to/image.jpg' \
https://graph.facebook.com/me/events

That event should have a picture.

They have recently added support for this to the PHP SDK: http://github.com/facebook/php-sdk/commit/08909f32d3adf296515fee531f6051e22caf62ec

I've forked their python-sdk and added multipart support, and added a simple put_event method that accepts a url for a picture, as well as the usual params. http://github.com/mscheibe/python-sdk

Michael Scheibe