I have been trying to send an automated message from my Facebook page to an open conversation. I have been using Graph API's /me/messages endpoint using Page Access Token, but it doesn't seem to work.
Following is the code
def sendMessage(to_id, msg):
print(f"Sending message to {to_id}")
url = f"https://graph.facebook.com/v13.0/me/messages?access_token={page_access_token}"
payload = {
"messaging_type": "RESPONSE",
"recipient": {
"id": to_id
},
"message":{
"text": msg
}
}
res = requests.post(url, payload)
print(res.content)
After calling this function, when I print the content of the response, it shows this:
b'{"error":{"message":"(#100) param recipient must be non-empty.","type":"OAuthException","code":100,"fbtrace_id":"A4QA9xqFj9Uch12oi6KRPQb"}}'
The error message is quite straightforward.
I think you should check again your param: to_id
, it could be empty or undefined/null in your case. Further check msg
if needed.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.