Facebook PHP SDK: Upload Event Cover Photo

自闭症网瘾萝莉.ら 提交于 2019-12-19 03:42:10

问题


I use the facebook-php-sdk to create an event for a page.

Now as described here it is possible to upload a picture to an event.

The problem with that is, that this is the profile picture. But since more than a year now, facebook provides new, large cover photos for events. I want to upload a picture to there, not as a profile picture. Is that possible? I didn't find any help on the Facebook Developer Graph Api Events Page as there only the way to upload a profile picture is described (HTTP POST TO /EVENT_ID/picture).

In short: Is it possible to upload a cover photo for an event via the Graph API?

UPDATE: I tried to upload a picture to the pages photo album and retrieve the picture id. I then tried to select this picture as the cover photo of the event.

$cover = array(
    'cover' => $uploaded_photo_id,
);          
$fb->api('/' . $this->FacebookEventID, 'POST', $cover);

Sadly, this isn't working as it is directly on pages.

I'm starting to think, that this isn't possible as of now.

Also if you set a cover photo via the website, you can query the graph api with https://graph.facebook.com/Event_ID?fields=cover which will return the cover.

UPDATE:

I still had no success. But if you answer, please keep in mind: I want to upload a cover picture to the event! NOT A PROFILE PICTURE


回答1:


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.




回答2:


yes. You can upload cover photo using Graph API. Once you have created the event, you can use cover_url field to upload the cover photo. 'cover_url' => url of the photo.




回答3:


I just figured out how to do it using the Facebook PHP SDK:

1- POST the Facebook event on the page using

$attachment = array(
    'access_token' => $access_token,
    'name' => $title,
    'start_time' => $start_time,
    'description' => $description
);
$res = $fb->api('/PAGE_ID/events/', 'post', $attachment);

2- Retrieve the EVENT_ID from the result of the post

$fb_event_id = $res['id'];

3- Update the event by calling /EVENT_ID with the cover parameter

$attachment['cover'] = '@/path/to/image.jpg';                                   
$fb->api('/'.$fb_event_id, 'post', $attachment);

That's it !!



来源:https://stackoverflow.com/questions/15725574/facebook-php-sdk-upload-event-cover-photo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!