在我的django项目中 我有这个功能:
def mesaj_yolla():
fbid="my_facebook_id"
post_message_url = 'https://graph.facebook.com/v2.6/me/messages?access_token=<my_access_token>'
response_msg = json.dumps({"recipient":{"id":fbid}, "message":{"text":"hello"}})
status = requests.post(post_message_url, headers={"Content-Type": "application/json"},data=response_msg)
print(status)
它返回:<Response [400]>
这些代码有什么问题?我只想向用户发送消息。
答案 0 :(得分:0)
根据API documentation,您应该使用recipients.id
代替recipients.user_id
:
def mesaj_yolla():
fbid="my_facebook_id"
post_message_url = 'https://graph.facebook.com/v2.6/me/messages?access_token=<my_access_token>'
response_msg = json.dumps({"recipient":{"id":fbid}, "message":{"text":"hello"}})
status = requests.post(post_message_url, headers={"Content-Type": "application/json"},data=response_msg)
print(status)
这解释了HTTP 400代码(错误请求)。