Creating a facebook event and publishing a cover p

2019-09-06 09:13发布

I'm creating a facebook event through the php sdk using

$param = array(
        'name' => $name,
        'start_time' => $ate,
        'description' => $description,
        'picture' => $photo            
    );

$facebook->api('/me/events', 'POST', $param);

Is it possible to set a cover photo for the event that is being created at this call? If not, can I set it somehow?

The documentation says that the cover field needs a photo id. If I haven't uploaded the photo yet, it doesn't have an id, so what do I do?

Do I upload the photo to the facebok account of user that issuing the "create event" action, getting that way the photo id, and then post it to the event?

What if I don't want to upload it to the users profile?

Thank you

2条回答
做自己的国王
2楼-- · 2019-09-06 09:49

To upload a cover photo of an event- Firstly, you cant do this while creating the event. You first have to create an event, as a result you'll get the event_id. Use this event_id, to make a call:

\POST /{event-id} with param: cover_url

That's the only way to do it as of now (I've tested). The method describe in this documentation dont work as of now, this is reported as a bug. You can subscribe to this bug to get any updates regarding the same.

Code:

$param = array(
    'cover_url' => '{image-link}'
);

$facebook->api('/{event-id}', 'POST', $param);
查看更多
forever°为你锁心
3楼-- · 2019-09-06 10:10

Code example, upload cover photo when create event:

<?php
//extract data from the post
extract($_POST);

//set POST variables
$url = 'https://graph.facebook.com/me/events';


$data["file"] = "@pika.jpg;type=image/jpeg";
$data["access_token"] = "PUT_USER_ACCESS_TOKEN_HERE";
$data["name"] = "testing";
$data["start_time"] = "2013-04-25";
$data["end_time"] = "2013-04-25";
$data["description"] = "coffee";
$data["location"] = "oldtown";
$data["privacy_type"] = "FRIENDS";

//make the POST request
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($curl);

 //curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "Content-Type: multipart/form-data; boundary=--$srand");

//close connection
curl_close($ch);

?>

Code example, After event created, you can also replace cover photo by upload new photo:

<?php
//extract data from the post
extract($_POST);

//set POST variables
$url = 'https://graph.facebook.com/PUT_EVENT_ID_HERE';


$data["file"] = "@pikachu.jpg;type=image/jpeg";
$data["access_token"] = "PUT_USER_ACCESS_TOKEN_HERE";

//make the POST request
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($curl);

//close connection
curl_close($ch);

?>
查看更多
登录 后发表回答