How do I retrieve a list of Facebook Business Pages?
I am trying to retrieve a list of all pages (business and non-business) that the account has. However, only non-business pages are currently being returned.
First I allow the user to login. He/she gets a Facebook Login popup, where he/she can select the pages. Then I generate a long-lived token, like so:
const response = await axios.get( "https://graph.facebook.com/v21.0/oauth/access_token", { params: { grant_type: "fb_exchange_token", client_id: process.env.FB_APP_ID, client_secret: process.env.FB_APP_SECRET, fb_exchange_token: fbAccessToken, }, } );
I get a token just fine. I return the token and the client makes an api call to retrieve the pages:
const handleFacebookCallback = async (response: any) => { if (!response?.id) { return; } setLoading(true); const { data } = await api.post("/api/integrations/facebook/user", { userId: user._id, fbAccessToken: response.accessToken, fbUserId: response.id, }); const url = `https://graph.facebook.com/v21.0/${response.id}/accounts?access_token=${data.longLivedToken}`; const fbResponse = await fetch(url); const fbData = await fbResponse.json(); setResponseFbPages(fbData.data); setLoading(false); };
Now, I have 3 pages - 2 are business and 1 non-business. Only the non-business pages are getting returned.
I tried to query the /accounts
endpoint, and I am expecting to get a full list of pages returned.