2014-12-17 2 views
5

나는이 세 가지 이미지에서는 image1.jpg,에서는 image2.jpg, image3.jpg.I는 하나의 post.Below 내 코드로 업로드하려고 :FaceBook Python SDK를 사용하여 여러 이미지를 업로드하는 방법은 무엇입니까?

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

그러나 그들은 분리 된 별도의 게시물로 업로드 얻을 하나의 게시물에 여러 이미지를 업로드하려면 어떻게해야합니까?

답변

0

시도해 보셨습니까? put-wall-post? .. 또는 put-object

put-wall-post 당신이 찾고있는 수 있습니다 :

첨부 - 벽에 게시되는 메시지에 대한 구조화 된 첨부 파일을 추가하는 DICT. URL을 공유하는 경우 첨부 파일 매개 변수를 사용하여 게시물에 미리보기 미리보기가 나타나게 할 수 있습니다.

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

0

이 시도는 형식의 DICT해야한다. 먼저 모든 사진을 업로드하고 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') 
관련 문제