Posts tagged with facebook-graph-api-v2.0

Issue: Getting 'Unsupported post request' error when accessing /accounts with WABA_ID despite having all required permissions:

  • whatsapp_business_messaging
  • whatsapp_business_management
  • Tech Provider verification
  • Full business verification

Error: 'Unsupported post request. Object with ID '[WABA_ID]' does not exist, cannot be loaded due to missing permissions.'

Tried:

  • New phone numbers
  • Fresh access tokens
  • Different WABA_IDs
  • Permission resets

Note: Can successfully send messages via API, but contacts API access fails. Request format appears correct, but permissions seem blocked despite having all verifications.

Meta support directs all technical issues to their Developer Forum, but the forum throws a ReactComponent error, making it inaccessible. Left without official support channels to resolve this.

Body:

I need to retrieve all daily metrics (e.g., impressions, reactions, video views) for my Facebook posts, videos, reels, etc., starting from their creation date. However, using Graph API v20.0 or higher, I only receive cumulative or incorrect data instead of individual daily values.

Here is what I’ve tried so far:

  1. Refreshing the Access Token:
    I've implemented token refresh logic to ensure a valid access token is always available.

  2. Fetching Metrics Daily:
    I request metrics using the insights endpoint with period=day. However, the results seem cumulative or incomplete.

Code Snippets:

1. Token Refresh Logic
The function below refreshes the token and saves it locally.

import requests from config import ACCESS_TOKEN, API_VERSION, CLIENT_ID, CLIENT_SECRET def refresh_access_token():     """Refresh the access token to get a new long-lived token."""     refresh_url = f"https://graph.facebook.com/{API_VERSION}/oauth/access_token"     params = {         'grant_type': 'fb_exchange_token',         'client_id': CLIENT_ID,         'client_secret': CLIENT_SECRET,         'fb_exchange_token': ACCESS_TOKEN,     }     response = requests.get(refresh_url, params=params)     if response.status_code == 200:         data = response.json()         new_access_token = data.get('access_token')         if new_access_token:             print("New token obtained:", new_access_token)             with open('access_token.txt', 'w') as token_file:                 token_file.write(new_access_token)             return new_access_token     else:         raise Exception(f"Error refreshing token: {response.status_code} - {response.text}") 

2. Fetch Daily Metrics for a Post
I fetch metrics using period=day, but the data is cumulative:

def fetch_daily_metrics(post_id, metrics, start_date, end_date):     token = get_access_token()     insights_url = f"https://graph.facebook.com/v20.0/{post_id}/insights"     params = {         'metric': ','.join(metrics),         'access_token': token,         'period': 'day',         'since': start_date,         'until': end_date,     }     response = requests.get(insights_url, params=params)     if response.status_code == 200:         return response.json().get('data', [])     else:         print(f"Error fetching metrics: {response.status_code}")         print(response.text)         return None 

3. Processing Metrics into Google Sheets
I use this to upload metrics into Google Sheets for analysis:

import pandas as pd from google_sheets import upload_to_google_sheets def process_and_upload_metrics(metrics_data):     rows = []     for metric in metrics_data:         name = metric['name']         for value in metric.get('values', []):             rows.append({'Date': value['end_time'], 'Metric': name, 'Value': value['value']})     df = pd.DataFrame(rows).pivot_table(index='Date', columns='Metric', values='Value').reset_index()     upload_to_google_sheets(df, "Facebook Insights", "Daily Metrics") 

Current Problems:

  1. Metrics are cumulative:
    I expected daily values but received cumulative ones. How can I ensure the API provides individual daily values?

  2. Data mismatch:
    Some metrics appear inconsistent with the Facebook UI insights.

  3. API Version:
    I’ve tested API versions from v15.0 to v21.0. Which version is recommended for daily metrics?

Any advice or suggestions would be greatly appreciated!


Tags:
[facebook-graph-api] [python] [google-sheets] [facebook-api]

Links:
Here’s the documentation I’ve been following.

Thank you for your help! 😊

I'm creating a datacollector which would fetch data from public available ad in order to retrieve it on my app.

Basically, I would like to create a copycat of the official tool from Meta on my application.

I followed the Meta Ad Library API Guide, generated the user token access and when I make a call (e.g. https://graph.facebook.com/v20.0/ads_archive?ad_reached_countries=["FR"]&search_terms=savon&access_token=MY_TOKEN) I always have this return :

{ "error": {     "message": "Application does not have permission for this action",     "type": "OAuthException",     "code": 10,     "error_subcode": 2332004,     "is_transient": false,     "error_user_title": "App role required",     "error_user_msg": "You need to be assigned a role by the app owner to continue. Learn more at https://developers.facebook.com/docs/development/build-and-test/app-roles",     "fbtrace_id": "AEtWDzYFQypjN8PvUhnHwSQ" } 

I've seen many issues identical to mine (another one here) and I don't really understand as my user is an administrator, of a fully verified business.

I even found people saying it's because the app doesn't have the correct scopes (such as : ads_read, public_profile). I can't add the scope "ads_archive" on my app as I can't see it anywhere in App Review > Permissions and Features on my developer account, otherwise everything seems okay, here is the debug of my token :

{ "data": {     "app_id": "APP_ID",     "type": "USER",     "application": "APPLICATION_NAME",     "data_access_expires_at": 1734880167,     "expires_at": 1727107200,     "is_valid": true,     "scopes": [         "read_insights",         "pages_show_list",         "ads_management",         "ads_read",         "business_management",         "pages_read_engagement",         "pages_read_user_content",         "public_profile"     ],     "granular_scopes": [         {             "scope": "pages_show_list"         },         {             "scope": "ads_management"         },         {             "scope": "ads_read"         },         {             "scope": "business_management"         },         {             "scope": "pages_read_engagement"         },         {             "scope": "pages_read_user_content"         }     ],     "user_id": "USER_ID" } 

}

How to finally access the public data ?