facebook-sdk icon indicating copy to clipboard operation
facebook-sdk copied to clipboard

Add a file parameter of put_object for uploading images

Open punkyoon opened this issue 7 years ago • 6 comments

It was related to #360.

A number of commit messages have been modified.

Usage

 graph.put_object(
     parent_object='post_id',
     connection_name='comments',
     message='Second!',
     file=open('image.jpg', 'rb'))

punkyoon avatar May 27 '17 18:05 punkyoon

@martey

long time no see. I will try to solve the problem asap.

punkyoon avatar Oct 08 '17 18:10 punkyoon

Sorry I'm late.

Facebook has disabled likes and comments through graph API.

So, I cannot test my pull request more. How do we do?

punkyoon avatar Apr 27 '18 16:04 punkyoon

If liking and/or commenting are no longer possible, don't worry about testing them.

martey avatar May 01 '18 06:05 martey

Hello, How's it going?

I tested to upload video object on the post using this code. however it was not working. because videos must be published to graph-video.facebook.com instead of graph.facebook.com (ref. https://developers.facebook.com/docs/graph-api/video-uploads)

So, I think this PR is only valid for uploading images now.

To upload the video, we should do like this example.

import requests


_user_id = ''    # user id (ex. 1603333222111000)
_token = ''    # Graph User API Token

url = 'https://graph-video.facebook.com/{user_id}/videos?access_token={token}'.format(
    user_id=_user_id
    token=_token
)

files = {
    'file': open('movie.mp4', 'rb')
}

response = requests.post(url, files=files).text
print(response)

punkyoon avatar Oct 06 '18 16:10 punkyoon

Hello,

I'm using python, and also using this function to send messages:

graph.put_object(txt_id, "messages", message = 'Message goes here')

How can I send a attachment or a photo?

PepeZuco avatar Mar 06 '20 13:03 PepeZuco

Hello,

I'm using python, and also using this function to send messages:

graph.put_object(txt_id, "messages", message = 'Message goes here')

How can I send a attachment or a photo?

graph.put_object(txt.id, "messages", message='Message goes here', source='url of the photo', link='any link you want to attach')

But how to attach files from local pc i still dont know

Polar1ty avatar Jul 08 '20 19:07 Polar1ty