使用Python将照片或视频上传到Facebook

使用Python将照片或视频上传到Facebook,python,facebook,video,upload,Python,Facebook,Video,Upload,我试图用Python将照片或视频上传到facebook页面,但我失败了 HTTPError:HTTP错误400:请求错误。但当我用表格代替时,它是好的。 让我给你看看密码 这是表单的代码 <!DOCTYPE html> <html> <body> <form enctype="multipart/form-data" action="https://graph-video.facebook.com/videos/PAGE_ID/photos?acce

我试图用Python将照片或视频上传到facebook页面,但我失败了 HTTPError:HTTP错误400:请求错误。但当我用表格代替时,它是好的。 让我给你看看密码

这是表单的代码

<!DOCTYPE html>
<html>
<body>

<form enctype="multipart/form-data"  action="https://graph-video.facebook.com/videos/PAGE_ID/photos?access_token=ACCESS_TOKEN"  
 method="POST">
<input name="file" type="file">
<input type="submit" value="Upload" />
</form>

</body>
</html>
我认为access_令牌不是问题所在,因为它在我使用表单时起作用

请让我知道如何通过Python上传视频或照片。谢谢。

这对我有用

 import requests
 url='https://graph-video.facebook.com/100000198728296/videos?access_token='+str(access)
 path="/home/abc.mp4"
 files={'file':open(path,'rb')}
 flag=requests.post(url, files=files).text
 print flag
flag将在成功上传视频时返回包含视频id的json,这对我来说很有用

 import requests
 url='https://graph-video.facebook.com/100000198728296/videos?access_token='+str(access)
 path="/home/abc.mp4"
 files={'file':open(path,'rb')}
 flag=requests.post(url, files=files).text
 print flag

flag将在成功上传视频时返回包含视频id的json

我猜您的问题来自第二个请求Python中缺少的enctype部分。我猜您的问题来自第二个请求Python中缺少的enctype部分。