10

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)

Community
  • 1
  • 1
Thorarin
  • 47,289
  • 11
  • 75
  • 111

5 Answers5

14

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.

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.

apaderno
  • 28,547
  • 16
  • 75
  • 90
Michael Scheibe
  • 171
  • 1
  • 3
  • Michael, thanks for this python fork, it works great. I had to make a small fix locally to get it to work though -- if you don't specify the 'id' parameter of 'put_event', it defaults to 'me/events', which crashes HTTPSConnection later in the code. It should be '/me/events'. Please update your fork when you have time. – Shaun Budhram May 18 '11 at 19:37
2

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.

Upload Photo To Album with Facebook's Graph API

I hope this helps.

thanks.

Community
  • 1
  • 1
Parth
  • 1,281
  • 8
  • 17
  • 1
    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 May 21 '10 at 14:43
  • 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. – Parth May 21 '10 at 15:35
1

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
  • 465
  • 5
  • 11
0

Here is a sample example using FbGraph written by Nov Matake in Ruby on Rails. I spend lots of hours to figure out, How to upload an image for an event. I hope this will help and save others time.

me = FbGraph::User.me(ACCESS_TOKEN)
event = me.event!(
  :name => 'FbGraph test event',
  :start_time => 1.week.from_now.to_i,
  :end_time => 2.week.from_now.to_i,
  :picture => File.new("/home/jeetu/Desktop/my_birthday.png")
)
Amitesh
  • 2,917
  • 2
  • 19
  • 14
-1

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
  • 47,289
  • 11
  • 75
  • 111