Attach Image to Facebook Event (PHP Sdk, Rest or Graph API)

Attach image to Facebook event (php sdk, rest or graph api)

Thanks everyone for your answers, I decided to revisit this to see if the API is working correctly now. It is! Uploading pictures with the Graph API now works. Thanks to Stan James for bringing my attention to this and giving code to post photos, which I adapted for events:

Setup:

//Setup the Facebook object allowing file upload
$facebook = new Facebook(array(
'appId' => 'xxxxxxxxxxxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxxxxxx',
'cookie' => true,
'fileUpload' => true
));

Post:

//Path to photo (only tested with relative path to same directory)
$file = "end300.jpg";
//The event information array (timestamps are "Facebook time"...)
$event_info = array(
"privacy_type" => "SECRET",
"name" => "Event Title",
"host" => "Me",
"start_time" => 1290790800,
"end_time" => 1290799800,
"location" => "London",
"description" => "Event Description"
);
//The key part - The path to the file with the CURL syntax
$event_info[basename($file)] = '@' . realpath($file);
//Make the call and get back the event ID
$result = $facebook->api('me/events','post',$event_info);

I have put all the code on pastebin (http://pastebin.com/iV0JL2mL), it's a bit messy from my debugging and getting angry with Facebook months ago! But it works.

Facebook PHP SDK: Upload Event Cover Photo

All answers above are wrong! There is only one way to create the Cover Image:

Create The Event:

$eventData = array(
'name' => 'Event Title',
'start_time' => 'StarttimeInCorrectFormat',
'description' => 'Event Description'
);
$fbEvent = $fb->api('/PAGE_ID/events/', 'post', $eventData);

Update the Event using the ID from above:

$cover['cover_url']     = 'http://urlToCoverImage.jpg';
$eventUpdate = $facebook->api( "/" . $fbEvent['id'], 'post', $cover );

return true or false.

And thats it. Cover is in.

How to upload a picture for an event using the Facebook Graph API?

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.

Upload Photo To Album with Facebook's Graph API

Here are some various ways to upload photos using the PHP Facebook Graph API. The examples assume you've instantiated the $facebook object and have a valid session.

1 - Upload to Default Application Album of Current User

This example will upload the photo to your default application album of the current user. If the album does not yet exist it will be created.

$facebook->setFileUploadSupport(true);
$args = array('message' => 'Photo Caption');
$args['image'] = '@' . realpath($FILE_PATH);

$data = $facebook->api('/me/photos', 'post', $args);
print_r($data);

2 - Upload to Target Album

This example will upload the photo to a specific album.

$facebook->setFileUploadSupport(true);
$args = array('message' => 'Photo Caption');
$args['image'] = '@' . realpath($FILE_PATH);

$data = $facebook->api('/'. $ALBUM_ID . '/photos', 'post', $args);
print_r($data);

Facebook graph api photo upload to a fan page album

This seems to be a bug with the Graph API. See this http://forum.developers.facebook.com/viewtopic.php?id=59063 (can't post links, yet)

Facebook: Can set the description and image of an event using the graph API?

I found the solution to this problem. Since I found many people searching for this solution, I posted the code to create an event with image using the facebook C# SDK.

Create a facebook Event with PICTURE (Javascript)

You can consider using the following solution

$photo = './images/logo-square.png';// Must be an image on your server
$event_info = array(
"privacy_type" => "OPEN",
"name" => "Event Title",
"page_id" => YOUR_PAGE_ID,
"start_time" => "2012-01-22 09:00:00",
"end_time" => "2012-02-22 09:00:00",
"description" => "Event Description"
);

//The key part - The path to the file with the CURL syntax
$event_info[basename($photo)] = '@' . realpath($photo);
//Make the call and get back the event ID
$result = $this->facebook->api($this->id.'/events','post',$event_info);

If you absolutely want to do in JS, make an ajax to execute this code and return the Event Id ($result["id"])

I did it and it worked perfectly.

ps: Thanks to Adam Heath who found the solution at Attach image to Facebook event (php sdk, rest or graph api)

Create a facebook Event with PICTURE (Javascript)

You can consider using the following solution

$photo = './images/logo-square.png';// Must be an image on your server
$event_info = array(
"privacy_type" => "OPEN",
"name" => "Event Title",
"page_id" => YOUR_PAGE_ID,
"start_time" => "2012-01-22 09:00:00",
"end_time" => "2012-02-22 09:00:00",
"description" => "Event Description"
);

//The key part - The path to the file with the CURL syntax
$event_info[basename($photo)] = '@' . realpath($photo);
//Make the call and get back the event ID
$result = $this->facebook->api($this->id.'/events','post',$event_info);

If you absolutely want to do in JS, make an ajax to execute this code and return the Event Id ($result["id"])

I did it and it worked perfectly.

ps: Thanks to Adam Heath who found the solution at Attach image to Facebook event (php sdk, rest or graph api)



Related Topics



Leave a reply



Submit