如何使用FaceBook Python SDK上传多个图像?

如何使用FaceBook Python SDK上传多个图像?,python,facebook,python-2.7,facebook-graph-api,Python,Facebook,Python 2.7,Facebook Graph Api,我有三张图片image1.jpg、image2.jpg、image3.jpg。我正试图将它们作为一篇文章上传。下面是我的代码: import facebook graph = facebook.GraphAPI(oauth_access_token) profile = graph.get_object("me") friends = graph.get_connections("me", "friends") file1 = open("image1","rb") file2 = open('

我有三张图片image1.jpg、image2.jpg、image3.jpg。我正试图将它们作为一篇文章上传。下面是我的代码:

import facebook
graph = facebook.GraphAPI(oauth_access_token)
profile = graph.get_object("me")
friends = graph.get_connections("me", "friends")
file1 = open("image1","rb")
file2 = open('image2', 'rb')
graph.put_photo(file1, 'Look at this cool photo!')
graph.put_photo(file2, 'Look at this cool photo!')
但是它们是在不同的图片中作为不同的帖子上传的。我如何在一篇帖子中上传多个图片?

你试过吗:。。或
put对象

放置墙柱
可能就是您要寻找的:

附件-在张贴到墙上的邮件中添加结构化附件的dict。如果要共享URL,则需要使用附件参数,以便在帖子中显示缩略图预览。它应该是以下形式的记录:


来源:

试试这个。首先,你必须上传所有照片并保留id(imgs_id)

然后,制作一个类似于args的dict,最后调用request方法

对不起,如果不是最好的压缩代码

    imgs_id = []
    for img in img_list:
        photo = open(img, "rb")
        imgs_id.append(api.put_photo(photo, album_id='me/photos',published=False)['id'])
        photo.close()

    args=dict()
    args["message"]="Put your message here"
    for img_id in imgs_id:
        key="attached_media["+str(imgs_id.index(img_id))+"]"
        args[key]="{'media_fbid': '"+img_id+"'}"

    api.request(path='/me/feed', args=None, post_args=args, method='POST')