How to upload multiple images using the FaceBook Python SDK?

I have three images image1.jpg, image2.jpg, image3.jpg. I am trying to download them as a single message. Below is my code:

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!') 

But they are loaded as separate records in separate images. How to upload multiple images in one post?

+5
source share
2 answers

Have you tried: put-wall-post ? .. or put-object

put-wall-post may be what you are looking for:

An attachment is a dictation that adds a structured application to a message that is sent to the wall. If you use a URL, you will need to use the attachment parameter so that a thumbnail appears in the message. This should be a form form:

Source: http://facebook-sdk.readthedocs.io/en/latest/api.html#api-reference

0
source

Try it. First, you must upload all the photos and save the identifier (imgs_id).

Then create a dict as args and finally call the request method.

Sorry if not the best compressed code ...

  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') 
0
source

Source: https://habr.com/ru/post/1209328/


All Articles