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

后端 未结 5 1957
慢半拍i
慢半拍i 2021-02-03 11:33

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

5条回答
  •  广开言路
    2021-02-03 12:29

    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.

提交回复
热议问题