I am trying to upload a file to Facebook send API via python requests. Curl to send API request is as follows
curl \
-F 'recipient={"id":"<PSID>"}' \
-F 'message={"attachment":{"type":"<ASSET_TYPE>", "payload":{"is_reusable":true}}}' \
-F 'filedata=@/tmp/shirt.png;type=image/png' \
"https://graph.facebook.com/v9.0/me/messages?access_token=<PAGE_ACCESS_TOKEN>"
I'm referring to this facebook documentation
I have tried the API using python requests
import requests
r = requests.get('https://homepages.cae.wisc.edu/~ece533/images/us092.pgm')
with open('temp.jpg', 'wb') as f:
f.write(r.content)
files = {
'recipient': (None, '{"id":" <USER_ID>"}'),
'message': (None, '{"attachment":{"type":"image", "payload":{"is_reusable":true}}}'),
'filedata': ('temp.jpg', open('temp.jpg', 'rb')),
}
url = "https://graph.facebook.com/v9.0/me/messages"
params = {"access_token":"<ACCESS_TOKEN>"}
response = requests.post(url=url,params=params, files=files)
print(response.content)
I'm getting response as follows
{"error":{"message":"(#100) Upload attachment failure.","type":"OAuthException","code":100,"error_subcode":2018047,"fbtrace_id":"Atv2YqLlb4ABkoVOW4sgnzd"}}
Following is the description of the error code
I can't figure out what I'm doing wrong