Pietro Luciani
Pietro Luciani

Reputation: 247

Create a facebook Event with PICTURE (Javascript)

I'm starting to use facebook graph api to create events with javascript! It works very well except for image. I create event in this way:

FB.api("/"+idOwner+"/events?access_token="+access_token,'post',{ 
    name: 'TEST',
    start_time: '2011-12-01T15:00:00',
    privacy_type:"OPEN",
    end_time: '2011-12-02T15:00:00',
        location: 'here',
    picture: 'http://www.ostianews.it/wp-content/uploads/2010/06/rock.jpg'              
});

idOwner and access_token are two variables. In this way it creates me event without picture. How can I load picture on my event???? Have a good evening!!! Bye!

Upvotes: 2

Views: 1104

Answers (1)

Jeremie Dupuis
Jeremie Dupuis

Reputation: 56

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)

Upvotes: 1

Related Questions