我尝试使用 Python 将照片或视频上传到 Facebook 页面,但出现 HTTPError: HTTP Error 400: Bad Request。但是当我使用表单时没关系。让我给你看代码。
这是表格的代码。
<!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>
这是我的 Python 代码。
video = open(args[0])
url = 'https://graph-video.facebook.com/videos/PAGE_ID'
data = {'access_token': 'ACCESS_TOKEN',
'title': 'test',
'description': 'test',
'source' : video
}
data1 = urllib.urlencode(data)
req = urllib2.Request(url, data1)
r = urllib2.urlopen(req)
我认为 access_token 不是问题,因为它在我使用表单时起作用。
请让我知道如何通过 Python 上传视频或照片。谢谢。