我想使用Python在Facebook上发布帖子,前提是帖子包含文本和多图像,我写了这段代码,
params = {
'access_token': 'MY_ACCESS_TOKEN',
'format': 'json'
}
image_urls = ['https://example.com/images/tw8qxmjwrb.jpg', 'https://example.com/images/g41oikacph.jpg']
temp_images = []
for url in image_urls:
response = requests.get(url)
if response.status_code == 200:
with tempfile.NamedTemporaryFile(delete=False) as file:
file.write(response.content)
temp_image_path = file.name
temp_images.append(temp_image_path)
uploaded_images = []
for temp_image in temp_images:
with open(temp_image, 'rb') as file:
files = {'source': file}
response = requests.post('https://graph.facebook.com/v11.0/PAGE_ID/photos', params=params, files=files)
if response.status_code == 200:
tmIMG = {"media_fbid": "{}".format(response.json().get('id'))}
uploaded_images.append(response.json().get('id'))
else:
print('Failed to upload image:', response.json())
for temp_image in temp_images:
os.remove(temp_image)
args = {
"message": "HELLO WORLD.",
"attached_media[0]": json.dumps({"media_fbid": uploaded_images[0]}),
"attached_media[1]": json.dumps({"media_fbid": uploaded_images[1]}),
"published": True
}
response = requests.post('https://graph.facebook.com/v11.0/PAGE_ID/feed', params=params, data=args)
print(response.status_code, response.json())
但我收到此错误:error':'message':'无效参数','type':'OAuthException','code':100,'error_subcode':1366051,'is_transient':False,'error_user_title': '已发布', 'error_user_msg': '这些照片已发布。
简单地说,我想在我的 Facebook 页面上发布一篇包含文本和多图像的帖子,我如何使用 python 来做到这一点?
已解决:解决办法很简单,上传单张图片时设置published:False
params['published'] = False;
已解决:解决办法很简单,上传单张图片时设置published:False
params['published'] = False;
为什么我无法在 Fewfeer v2 中发布提示?