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 o
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
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")
)
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.
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.
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.