python - 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 GB
- 视频文件必须少于 20 分钟
我的视频长度为 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作为参数,但它不起作用
我错过了什么?
解决方案
就像@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)
推荐阅读
- bash - 在后台运行进程,直到在 bash 脚本中停止
- php - 数据未插入表,数据库连接没有错误
- windows - 使用 WinSCP 和批处理文件在 SFTP 服务器上创建文件夹(当它不存在时)
- keras - 如何在 keras 中获取批次中每个样本的损失?
- amazon-s3 - ValueError: Error when checking target: expected dense_2 to have shape (10,) but got array with shape (9,)
- python-3.x - 使用 numpy 的 2d 图像数组中的 Logical_And
- scala - 如何使用相同的逻辑迭代 RDD
- ag-grid - Ag-grid:具有树数据的全宽度分组行
- php - 为什么php-fpm(nginx)进程不关闭并不断累积?
- python-3.x - Python 3 - 无法在“if”语句下调用函数