Posts tagged with facebook-graph-api

I'm currently working on a workflow to fetch all posts made by my company on social medias. On Facebook, I'm currently using the ads_posts endpoint to fetch both organic and paid posts (was previously using /feed for organic posts and /ads on the business account for paid posts, however the ads endpoint was lacking some posts that were created through dynamic ads).

The current request is like this:

https://graph.facebook.com/v21.0/{FB_PAGE_ID}/ads_posts?fields=id,created_time,updated_time&include_inline_create=true&access_token={PAGE_ACCESS_TOKEN}.  

The problem is, this endpoint only gets me data from within about a month ago. Any try to fetch data older than that using the filters "since" and "until" returns no data, and trying to go there manually through pagination gets me an error of:

Please reduce the amount of data you're asking for, then retry your request

(the "limit" filter doesn't help with this either).

Am I missing something here? Is this a limitation of the ads_posts endpoint? I couldn't find anything related to this on the API reference.

Also, i saw that the posts returned via /ads_posts are sorted by their creation time, while the ads fetched on the /ads are sorted by their update time. Is there any way to change the sorting of the ads_posts entries to their update time as well?

Thanks in advance!

Using https://graph.facebook.com/v21.0/{AD_ACCOUNT_ID}/ads?fields=id,created_time,updated_time,creative{effective_object_story_id}&access_token={USER_ACCESS_TOKEN} i'm able to get ads from 2024-12-01 and before, with their effective_object_story_id that I can access through the post endpoint and check that they in fact exist.

Using the mentioned /ads_posts request, it gets me only posts as old as from 2024-12-06 (3101 posts total). Anything older than this gets me an error or no data at all.

All the posts have been published the same way, and the tokens used have all the needed permission.

My client has an ad agency. I have to develop a comprehensive reporting of all the ads running currently, cost per lead and other details. I don't have much experience with Meta APIs, they have already given me full access to their entire business portfolio, ad accounts and pages.

The problem I am facing is that there does not seem to a straightforward way to achieve this. Even though I have full privileges, I am unable to figure it. This is what I have thought:

  1. get Meta realtime updates through their webhooks.
  2. call Meta API when necessary.

I am stuck on the first step. I am following the instructions on this page: https://developers.facebook.com/docs/graph-api/webhooks/getting-started It asked to do the following two things and I have done it

Create an endpoint on a secure server that can process HTTPS requests. Configure the Webhooks product in your app's App Dashboard. 

Now, to get the updates of Leads, I am following the instructions on the page: https://developers.facebook.com/docs/graph-api/webhooks/getting-started/webhooks-for-leadgen

It asks:

Install your app using your Facebook page 

these are the steps mentioned to install the app on Facebook page but the instructions are broken.

  1. Select your app in the Application dropdown menu. This will return your app's access token.

  2. Click the Get Token dropdown and select Get User Access Token, then choose the pages_manage_metadata permission. This will exchange your app token for a User access token with the pages_manage_metadata permission granted.

  3. Click Get Token again and select your Page. This will exchange your User access token for a Page access token.

  4. Change the operation method by clicking the GET dropdown menu and selecting POST.

  5. Replace the default me?fields=id,name query with the Page's id followed by /subscribed_apps?subscribed_fields=leadgen, then submit the query.

  6. Select your app in the Application dropdown menu. This will return your app's access token. IT doesn't..

  7. in step 2, the moment I select User access Token, a popup opens which asks to reconnect the app. there is no time to choose pages_manage_metadata. cannot move beyond this. I have already tried several things out of frustration, searched on google, ask ChatGPT and Gemini. Nothing seem to work.

I don't understand why this is so difficult and confusing when I have the full rights and doing it just for myself. If I had this public app on which multiple people were able to connect, but just for an in-house things, it seems unnecessarily complicated.

if anyone can, please help.

I created a sandbox ad account on Facebook API then created a system user, put all the permissions on it and associated it with this sandbox ad account to be able to create the ads but when I try to create an ad it asks to add a payment method.

How can I add a payment method to an account that should be a test account?

How do I resolve this?

Apologies for what should be a basic question, but i've hit the end of my rope. I'm trying to resurrect an old project that used the instagram API to search for posts based on a given hashtag (long before the graph API). Previously this was very simple to go to the developer page, apply for an API token and then hit the URL. Things have changed massively with the newer graph endpoints and i'm struggling to understand what to do, and hitting bugs/issues with facebooks developer tooling at every step of the way

What I want to do:
Given a hashtag string, find the hashtag id and then poll this endpoint once, lets say, every 30 seconds: https://developers.facebook.com/docs/instagram-platform/instagram-graph-api/reference/ig-hashtag/recent-media

Later I want to try search for comments on these posts too, but that will depend on a few things as I go

Whats wrong:
Every attempt to make use of this (by creating an app on the dashboard, waiting for verification, and generating a token) just keeps returning that the token is invalid, or the account is not valid. Lots of the documentation seems to be out of date and referencing an older setup. Some docs say that this endpoint requires a business account + business app. Although I didn't want to, I migrated my personal instagram account to a business account, and tried to create a business app which is an extremely convoluted process requiring business verification, for simple access to an endpoint. I don't have a business so I can't fully complete this process.

I've tried to ask for help via the meta developer community, but it won't load for many days now:

If I try jump directly into the instagram community section via google, it will load, but I keep getting a popup to say that my profile is incomplete. If I click to complete, it doesn't do anything. If I dismiss it, it just keeps popping up. If I go directly to my profile, it won't let me add anything. The community page won't let me do anything without the profile

I've tried to report a bug via the tool, but it tells me I can't do that here, as this bugs should be directed to the community portal ... which I can't get into

... this has been an EXTREMELY painful experience over the course of several days which has me regretting trying to use instagram again

What I need:
Can someone please provide step-by-step instructions on what I need to do to create the appropriate access token to hit this endpoint. Including the process of creating whichever type of developer app I need in the dashboard.

I don't have a server, a domain, a business, or even a project name ... i'm simply trying to generate a once off access token, hit this endpoint via a project running on my local machine to experiment with an idea. Thanks

I am implementing Facebook OAuth for user sign-in following facebook-login/guides/advanced/manual-flow. When the user clicks "Sign in with Facebook," a popup window opens at https://my-domain/login, which redirects to Facebook's OAuth URL (e.g., https://www.facebook.com/v21.0/dialog/oauth?...). Initially, window.opener correctly points to the parent window that opened the popup.

However, after the user completes the login (e.g., clicks "Continue as [Username]") and is redirected back to https://my-domain/login, window.opener unexpectedly becomes null. Since window.opener shouldn't become null during this process, this behavior is breaking my implementation, as I rely on window.opener.postMessage() to send the redirect URI back to the main window.

This issue occurs in all Android browsers (e.g., Chrome, Firefox, Opera) but works correctly on desktop browsers. Other OAuth providers like Google, Github, etc. works fine on both Android and Desktop browsers. Facebook works on Desktop browser, but window.opener becomes null in Android browser. In the network tab, I noticed that desktop browsers make requests to www.facebook.com, while Android browsers make calls to m.facebook.com. Why does window.opener become null on Android browsers, and how can I resolve this?

Additional Reproduction Steps:

  1. Enable remote debugging on an Android browser using Chrome DevTools.

  2. Open a new tab and run the following in the Console tab: window.open(LOGIN_PAGE_URL);

    Replace LOGIN_PAGE_URL with a site supporting Facebook login (e.g., https://leetcode.com/accounts/login/).

  3. In the popup window, run: window.opener;

    It correctly returns the parent window reference.

  4. Click "Sign in with Facebook." On the Facebook login page, window.opener still returns the correct reference.

  5. Complete the login. After redirecting back to the original page, window.opener unexpectedly becomes null. Because window.opener becomes null, I am unable to send redirect_uri by doing window.opener.postMessage() from popup window to my opener window.

    Example code to reproduce the same error:

    <!-- Parent window --> <html>   <body>     <button id="login-btn">Sign in with Facebook</button>     <script>       document.getElementById("login-btn").onclick = () => {         const popup = window.open("https://my-domain/login", "_blank", "width=600,height=600");         window.addEventListener("message", (event) => {           if (event.origin === "https://my-domain") {             console.log("Received message from popup:", event.data);           }         });       };     </script>   </body> </html> <!-- Popup window --> <html>   <body>     <script>       // Redirects to Facebook login       window.location.href = "https://www.facebook.com/v21.0/dialog/oauth?response_type=code%2Cgranted_scopes&client_id=CLIENT_ID&state=STATE_STRING&scope=public_profile%2Cemail%2Cuser_likes&redirect_uri=https://my-domain/login";       // After redirect back from Facebook       window.onload = () => {         if (window.opener) {           window.opener.postMessage({ redirect_uri: window.location.href }, "https://my-domain");         } else {           console.error("window.opener is null");         }       };     </script>   </body> </html> 

    Client ID can be retrieved by registering a web-app in https://developers.facebook.com/.