I was trying to implement Facebook Checkbox for my customers but I realized that it's required to subscribe to the messenging_optins
event to render Facebook checkbox. So I tried to subscribe to the messaging_optins
event programmatically.
Note that my facebook app is in development app. So in fact, I still test on my Facebook account.
curl -i -X POST "https://graph.facebook.com/v3.2/{my-customer-page-id}/subscriptions?access_token={my_app_access_token}&callback_url=https%3A%2F%2Fmy-server.ngrok.io%2Fwebhook%2Ffacebook&fields=messaging_optins&object=page&verify_token=abc123abc123456"
The response is {"success":true}
But my Facebook Checkbox still does not work until manually go to Facebook Developer setting and subscribe to the Page as the below screenshot.
I realize that the above curl
command just help me subscribe to the Page Webhook (not Messenger webhook) event as the below screenshot.
Can anyone point me out why I can't subscribe to "Messenger event" but Facebook graph API return that it successfully subscribed?
Thanks.
After 1 day digging Facebook Docs, try and test many cases with Facebook Graph Explorer, I finally found the way to programmatically subscribe to the Page's Webhook.
In Facebook Docs, it had writes 3 lines like this
Webhooks for Messenger allows you to receive real-time notifications when a variety of interactions or events happen, including when a person sends a message. Webhooks for Messenger works a little differently than other Webhooks so please use the Webhooks for Messenger docs when setting up this type of Webhook.
Here is the way I subscribe messages
, messaging_postbacks
, messaging_optins
, message_reads
events. Refer to: https://developers.facebook.com/docs/graph-api/webhooks/getting-started/webhooks-for-pages
curl -i -X POST "https://graph.facebook.com/v3.2/{page-id}/subscribed_apps?access_token={page-access-token}&subscribed_fields=messages,messaging_postbacks,messaging_optins,message_reads"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With