How to Unsubscribe an app for all Facebook pages Webhooks - facebook

I have a Facebook App which is subscribed to more than 20,000 pages. The server isn't able to process hooks from all these Facebook pages, I want to unsubscribe my app from all these Facebook pages. Is there a quicker way to do this. Most of the page access token I have is expired, so I can't loop through all the pages and unsubscribe my app from them.

To unsubscribe your app from a Facebook page, you do not need a token from the page. All you need is your App Access Token. To unsubscribe from the page just make a DELETE http request to:
https://graph.facebook.com/{page_id}/subscribed_apps?access_token={your_access_token}
You can get your App Access Token by sending a GET request to:
https://graph.facebook.com/oauth/access_token
?client_id={app-id}
&client_secret={app-secret}
&grant_type=client_credentials
So just make a DELETE request to each page you want to unsubscribe from.

Related

Facebook Webhooks doesn't receive any message

I have a Developer Account, I have a Facebook Fans Page, and I have a Facebook App which link to Facebook Fans Page. I also deploy the backend to heroku successfully. And I also have access token, and Webhooks url and verify token still complete.
Through the curl by cmd, the backend receive message successfully. But through the Facebook Messenger webpage to send message, the backend can't receive any message from any user.
Why???
https://developers.facebook.com/docs/messenger-platform/getting-started/app-setup/
I follow this document, but not working.

Facebook Messenger - add pages to my facebook app

I'm developing app which allows me to chat with customers via messenger. I'm chatting as a Page. I had to add that page into Facebook app -> Messenger -> Settings -> Access Token. It all works fine but is there any way to make that via API? I wanna add more pages on which I'm not admin. In fact I wanna allow admins to add theirs pages using my app.
Yes you can do that and this is the process
1: First thing first you will make a facebook login button with this scope pages_show_list when user clicks on it he/she can select as many page as he want, after the login flow completed you should have a App-Scoped User Access Token
2: since you had the pages_show_list scope when user signed in you now have the ability to call to this endpoint using the user access token graph.facebook.com/me/accounts?fields=name,access_token&access_token=[USER ACCESS TOKEN] after requesting for this endpoint you will get a list of the pages that the user was selecting in the login flow and you now will see that in the response you have name and access_token for each page
3: grab an access token of the page you want and post to this endpoint graph.facebook.com/{page-id}/subscribed_apps?subscribed_fields=feed,[and any other fields you want to subscribe to]&access_token=[USE THE PAGE ACCESS TOKEN]
after that you should get a success response and now your app is subscribed to the Facebook page

Allowing others to connect their Facebook Page to our App

I created a Facebook app that has a webhook for Facebook Page messages through FB Messenger. Essentially the purpose is to add a bot to our Facebook Pages. We now want to start creating Messenger bots for other business' pages.
Facebook allows us to have our app webhook subscribe to our own FB Pages, but we can't find any way to add another business' FB Page (screenshot below)
How can we make it so that our app can be installed by other businesses to their FB Pages? (so that the bot will work for their pages).
We put our app through the app review process and it was approved, but I only put in my personal information, not the business' information. Could this be a blocker?
You can subscribe pages to / unsubscribe them from your webhook via the page/subscribed_apps API endpoint.
You need to have a page admin login to your app and grant it permission to manage their pages, then you get a page access token, and with that you make the request to subscribe the page to your webhook.

Connecting third party Facebook page via messenger api

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.

How to deal with the deprecated offline_access?

I have an application which uses offline_access to get permanent access to different pages.
Users can install this application and add it to pages, where they are admins.
With an external Backend they can administrate their app and let it post different things (Competitions, ...).
So they don't have to stay logged in to Facebook.
Now... there is the problem...
On May 1st the offline_access permission will be removed and the customers have to get a new Token for their Pages every 60 days.
Since now I'm using the offline_access feature for our customers to get non-expiring Page-Tokens.
Is there any workaround for that?
Often it's just a Facebook sub-account of the customers to run the app. So it's possible that they don't login for 60+ days = the access token will expire and the application won't work.
redirect them to a link of your app in facebook when their access token expired like this
http://apps.facebook.com/xxx/reaccess.php?ref=REF_URL
Get new access_token & redirect user back to your app's original page again
i dont think you be needed to ask them again for permissions
Remind the user to re-authorize access before the expiration of the token. Do this by sending them an app-to-user request and and an email (because app-to-user requests don't generate a notification). In the email include a link directly to a web page which instantly pops up the authorization dialog (and do something similar with the app-to-user request).