Posts tagged with facebook

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?

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/.

I am trying to implement Facebook login for my application. It was working well in development mode, but when I try to switch to live mode I see this message:

Feature Unavailable

Facebook Login is currently unavailable for this app, since we are updating additional details for this app. Please try again later.

here is the exact error I get

I do not have any required actions in developer console.

I have searched for an answer, I have already set advanced access to email and public profile, and I got advanced access to other permissions as well. Business verification is complete and I have verified my Business as a tech provider as well.

Here is the code that handles the Facebook login (I am using Django framework):

def facebook_login(request):     facebook_auth_url = "https://www.facebook.com/v21.0/dialog/oauth"     if "test" in request.get_full_path():        redirect_uri = request.build_absolute_uri('/test/home/facebook_login/facebook_callback/')        redirect_uri = "http://localhost:8000/home/facebook_login/facebook_callback/"     else:         redirect_uri = request.build_absolute_uri('/home/facebook_login/facebook_callback/')     scopes = "pages_show_list,business_management,read_insights,ads_read,pages_read_engagement,ads_management"          state = generate_state()     request.session['oauth_state'] = state          params = {         'client_id': settings.META_APP_ID,         'redirect_uri': redirect_uri,         'scope': scopes,         'response_type': 'code',         'state': state,     }     auth_url = f"{facebook_auth_url}?{urlencode(params)}"     return JsonResponse({'authorization_url': auth_url}) def facebook_callback(request):     error = request.GET.get('error')     if error == 'access_denied':         prefix = 'test/' if os.getenv('PROD') == 'blue' else ''         cancel_redirect_url = (             "http://localhost/" + prefix + "#/home/connections"              if os.getenv('DEVELOPMENT') == 'True'              else "https://platform.webalyze.ai/" + prefix + "#/home/connections"         )         return redirect(cancel_redirect_url)          state = request.GET.get('state')     if state != request.session.pop('oauth_state', None):         return JsonResponse({'error': 'Invalid state parameter'}, status=400)     code = request.GET.get('code')     if not code:         return JsonResponse({'error': 'No code provided'}, status=400)     token_exchange_url = "https://graph.facebook.com/v21.0/oauth/access_token"     redirect_uri = request.build_absolute_uri(request.path)     print('REDIRECT (facebook_callback):', redirect_uri)     params = {         'client_id': settings.META_APP_ID,         'redirect_uri': redirect_uri,         'client_secret': settings.META_APP_SECRET,         'code': code,     }     response = requests.get(token_exchange_url, params=params)     data = response.json()     if 'access_token' in data:         access_token = data['access_token']         saveMetaTokenToDatabase(request.user, access_token)         prefix = 'test/' if os.getenv('PROD') == 'blue' else ''         if os.getenv('DEVELOPMENT') == 'True':             return redirect("http://localhost/" + prefix + "#/home/connections")         else:             return redirect("https://platform.webalyze.ai/" + prefix +"#/home/connections")     else:         return JsonResponse({'error': 'Failed to obtain access token'}, status=400) 

What am I missing so I can do this in live mode?

I'm trying to setup webhook for Facebook webhook, I got my php script to run just fine with the test feed. The app is subscribed to the "Feed", as I want to get if a post is made on our public page. But eventho my app now is Live, I'm still not recieving any post requests other than the test one, when I test it.

I read the documentation, and it seems like its cause it need "pages_read_engagement" permision via App Review.

But here is my problem, how do I request for this permision, as a app review want you to have a Facebook login on page and such, but when its just a webhook that recieves, translates and put into our database to be displayed on website, it realy does not use login an such.

Any one know how to do this, I've been stuck on this for some time now.