I'm trying to subscribe a Facebook page to my facebook app. It's a messenger app where I need to subscribe the page to my webhook added in the app.
Using the graph API, I have the page access token and page id, I have tried the subscribed_apps API but it didn't work
FB.api('/' + page.id+ '/subscribed_apps?access_token=' +
page.access_token,function (response) {
console.log(response)
});
Is there an API to make the page to subscribe to my webhook in the app.
It is described in the Graph API reference:
https://developers.facebook.com/docs/graph-api/reference/page/subscribed_apps/#Creating
You can you the below API to subscribe the page to your webhook. Specify the fields you want to subscribe to using the subscribed_fields query parameter depends on your use case.
`curl -i -X POST "https://graph.facebook.com/{page-id}/subscribed_apps
?subscribed_fields=feed
&access_token={page-access-token}"`
Example - If your use-case is related to page messaging use messages,message_echoes fields as subscribed_fields.
Note - Your page access token should have pages_messaging permission.
Related
I am working on a messenger platform that uses a messenger webhook to receive messages, and the Graph API to send messages. I currently need to go into my app settings and choose to subscribe pages that I already own.
I am wondering how I can subscribe pages that I don't own to my webhook. Is this possible if I have the Page Access Token? I can build an OAuth2 flow to get the Page Access Token, but I don't see what to do with it once I have it.
Any help is appreciated.
This can be achieved by making a POST call to /{page-id}/subscribed_apps endpoint with your Page Access Token.
API reference docs are at https://developers.facebook.com/docs/graph-api/reference/page/subscribed_apps/
I have an application that uses the Facebook messenger api to send and receive messages through a Facebook page. This works great. Now I need to be able to have a user in my application link their page so that messages sent to their page will send webhooks to our endpoint, and also give us the ability to send messages through that page using an auth_token.
Is there any way to do this via api, or will each user have to manually create a Facebook app, generate an auth_token for their page, and set the webhooks url to our endpoint? I've read about messenger account linking but I don't think it's quite what I need, as I'm not just looking to request additional profile information.
After looking a bit deeper, I found that in order to do this you must perform an OAuth flow to get an auth_token for the user, then use the graph api to get an auth_token for the desired user's page. Then with the page auth_token you can make a POST request to the subscribed_apps endpoint, which will then add the page to the app's webhook events.
I want to be able to do this programmatically. I am currently using the Koala gem like this
page_token = #user_graph.get_page_access_token(page_id)
but page_token doesn't work when I use it to subscribe the page to my messenger bot. However, the page access token generated from the token generation section of messenger works.
I want to pull events from any facebook page(given a page id) using REST Api. I am writing a server application and there is not facebook user login that we are using.
You could do this with an eternal Page Access Token via the /{page_id}/events edge.
See
https://developers.facebook.com/docs/graph-api/reference/page/events/
I am developing a facebook application, I want to remove my application from a user using Graph API, is there any way to do this.
When the user is connected, do:
FB.api("/me/permissions","DELETE",function(response){
console.log(response); //gives true on app delete success
});
I got this working with a serverside request using Using ASP.Net with Facebookâs Graph API and OAuth 2.0 Authentication this article as reference you get a auth token then when they redirect back to your callback you post a delete request to the graph url e.g.
"https://graph.facebook.com/person_id/permissions?access_token=token