首页 > 解决方案 > Facebook Graph API POST 视频上传源参数不起作用

问题描述

它适用于任何地方托管的视频文件上的file_url,但不适用于带有source参数的本地视频文件

这是我的 POST 请求的 python 代码:

import requests

url2 = 'https://graph-video.facebook.com/v10.0/105868438278259/videos'
myobj2 = {
    'access_token': '****',
    'source': 'file_example_MP4_480_1_5MG.mp4', #it's in the same folder
    'title': 'test title 123456',
    'description': 'Video description',
    }

x2 = requests.post(url2, data = myobj2)
print (x2.text)

我正在使用 Facebook Graph API v10,不可恢复上传,唯一的限制是:

我的视频长度为 1 分钟,大小为 5 mb,但我收到了以下回复:

{"error":{"message":"There was a problem uploading your video file. Please try again.","type":"OAuthException","code":390,"error_subcode":1363030,"is_transient":true,"error_user_title":"Tiempo de espera agotado al subir el video","error_user_msg":"Se agot\u00f3 el tiempo de espera antes de que se terminara de subir el video. Probablemente se debe a una conexi\u00f3n de red lenta o a que el video que intentas subir es demasiado grande. Vuelve a intentarlo.","fbtrace_id":"AFTgEBhNlaGPyWaGs_RFi-y"}}

我没有低速连接,根据限制我的文件不是太大

这是来自 Facebook Graph API 的文档 https://developers.facebook.com/docs/video-api/guides/publishing/?locale=en_US#non-resumable-upload

我也尝试添加content-type: video/mp4作为参数,但它不起作用

我错过了什么?

标签: pythonfacebookfacebook-graph-apirequesthttp-post

解决方案


就像@WizKid 所说,它应该是一个文件而不仅仅是一个路径,在 facebook 文档中并不清楚如何添加本地文件,现在它的工作方式如下:

url = 'https://graph-video.facebook.com/v10.0/105868438278259/videos'
fp = 'file_example_MP4_480_1_5MG.mp4'

files = {'source': open(fp, 'rb')}
payload = {
    'access_token': '****', 
    'title': 'test title 12345667657',
    'description': 'Video description 1',
}

response = requests.post(url, files=files, data=payload, verify=False)

推荐阅读