Answer the question
In order to leave comments, you need to log in
How to upload a video to Facebook?
I'm implementing a resumable download, the problem occurs when a chunk is directly applauded.
Option 1, as per the docks
file = open('C:\\Users\\maxim\\Downloads\\ya.mp4', 'rb')
data = dict(access_token=user.fb_token, upload_phase='transfer',
start_offset=int(kwargs.get('start_offset')), upload_session_id=int(kwargs.get('upload_session_id')),
video_file_chunk=file
)
# optional destination
url = '%s%s/videos' % (self.api_video, user.fb_user_id)
# Headers
headers = {'Content-type': 'multipart/form-data'}
req = requests.post(url=url, data=data, headers=headers)
{'start_offset': 0, 'video_file_chunk': <_io.BufferedReader name='C:\\Users\\maxim\\Downloads\\ya.mp4'>, 'upload_phase': 'transfer', 'upload_session_id': 249691982228348, 'access_tok
en': 'EAAXFFwnmYScBABTx6AT40zg1OcQLpSzPd9RBSYAEwqShNvDHLgFCb7A5FnUkvhZAWo0dzhX0Y6NRZADj50JbFqjExR39gnhWGgbjOfqpfiYPsm71NMwKPI94oFmoJf3cWFjHEUAZAwZDZD
'}
'https://graph-video.facebook.com/v2.8/1151655156896/videos'
{'error': {'code': 100, 'message': "Unsupported post request. Object with ID '1151655156896' does not exist, cannot be loaded due to missing permissions, or does not support this o
peration. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api", 'fbtrace_id': 'FEoBntf5jqV', 'error_subcode': 33, 'type': 'GraphMethodException'
}}
video_file = {'video_file_chunk': open('C:\\Users\\maxim\\Downloads\\ya.mp4', 'rb')}
data = dict(access_token=user.fb_token, upload_phase='transfer',
start_offset=int(kwargs.get('start_offset')), upload_session_id=int(kwargs.get('upload_session_id')),
)
# optional destination
url = '%s%s/videos' % (self.api_video, user.fb_user_id)
# Headers
headers = {'Content-type': 'multipart/form-data'}
req = requests.post(url=url, files=video_file, data=data, headers=headers)
{'error': {'code': 100, 'message': "Unsupported post request. Object with ID '1151655156896' does not exist, cannot be loaded due to missing permissions, or does not support this o
peration. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api", 'type': 'GraphMethodException', 'fbtrace_id': 'A1KZqqvi5pI', 'error_subcode': 33
}}
Answer the question
In order to leave comments, you need to log in
from requests_toolbelt.multipart.encoder import MultipartEncoder
m = MultipartEncoder(
fields=dict(
access_token=user.fb_token,
upload_phase='transfer',
start_offset=kwargs.get('start_offset'),
upload_session_id=kwargs.get('upload_session_id'),
video_file_chunk=('chunk1.mp4', open(video_file_chunk, 'rb'),
'multipart-form/data'),
)
)
url = '%s%s/videos' % (self.api_video, user.fb_user_id)
req = requests.post(url=url, data=m, headers={'Content-Type': m.content_type})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question