Posts tagged with facebook-ads-api

I am currently working with the Meta Business Manager and the Facebook Graph API. In the Meta Business Manager UI, under Business Info, I can see a field labeled Ad account creation limit, which shows the maximum number of ad accounts that can be created for a particular business.

However, I am unable to find any relevant endpoint or field in the Facebook Graph API documentation that would allow me to fetch this information programmatically. I have searched through the available endpoints for businesses and ad accounts but haven’t found anything that matches.

Does anyone know if it's possible to retrieve the Ad account creation limit via the Facebook Graph API? If so, could you point me to the correct endpoint or provide an example of how to fetch this data?

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 ?

The request I am making is:

[GET] graph.facebook.com/v20.0/[ad_id]/adcreatives?fields=name,url_tags

The Facebook API is bringing me this:

{   "data": [     {       "name": "{{product.name}} XXXX",       "url_tags": "utm_source={{site_source_name}}&utm_medium={{placement}}&utm_campaign={{campaign.name}}&utm_content={{ad.name}}",       "id": "XXXXX"     }   ] } 

I want to translate the url_tags and name fields so that it brings me the real url and name that will be displayed for that creative.

I tried to read the documentation and test all parameters, but I didn't find anything.

I am trying to create an APP ENGAGEMENT campaign using Facebook ads API. I want to optimize (performance goal) the adset based on custom/standard events associated with the app; not based on clicks or app installs.

I am setting optimization_goal as OFFSITE_CONVERSIONS. Inorder to pass promoted_object, the event name is required. Promoted object will be passed as

{    "application_id" : <APP_ID>,    "object_store_url" : <APP_URL>,    "custom_event_type" : <EVENT_TYPE> } 

In Ads manager UI; when I select the app all the events associated with app are displayed. If no events are associated with the app, it's asking to create an event. How to get all these events via Ads API?

I'm encountering an issue with the Facebook Graph API when filtering leads based on the time_created field using UNIX timestamps. It seems that the API's time filtering is not precise down to the second.

For example, if I filter leads created at 06-07-2024 11:58:00 AM (actually in UNIX timestamp) and a lead has a time_created value of 06-07-2024 11:58:12 AM, the lead is still included in the response, resulting in duplicates in my data.

Has anyone else experienced this issue or found a way to ensure the filtering is precise to the second?

My Code:

$currentDateTime = Carbon::now(); //At Very Start of Code. $lastestDate = Carbon::parse(LeadData::latest()->first()->last_processed_time)->getTimestamp(); . . . . $newUrl2 = "https://graph.facebook.com/v20.0/{$adId}/leads"; $paramsNew2 = [     //'since' => $lastestDate,     'filtering' => json_encode([         [             'field' => 'time_created',             'operator' => 'GREATER_THAN', //_OR_EQUAL             'value' => $latestDate, // 1720247400, getting it from DB as last_processed_time.         ]     ]),     'fields' => "id,form_id,platform,partner_name,field_data,ad_id,adset_id,campaign_id,ad_name,adset_name,campaign_name,created_time,post",     'access_token' => $accessToken, ]; $response2 = Http::get($newUrl2, $paramsNew2); $data3 = $response2->json(); $leadDatas = $data3['data'] ?? null; foreach ($leadDatas as $leadData)  {     try      {         LeadData::create([                 'account_id' => $adAccountId ?? null,                 'account_name' => null, ///$accountName,                 'campaign_id' => $leadData['campaign_id'],                 'campaign_name' => $leadData['campaign_name'],                 'adset_id' => $leadData['adset_id'],                 'adset_name' => $leadData['adset_name'],                 'ad_id' => $leadData['ad_id'],                 'ad_name' => $leadData['ad_name'],                 'ad_status' => $adStatus,                 'lead_id' => $leadData['id'],                 'lead_created_time' => $leadData['created_time'],                 'platform' => $leadData['platform'],                 'form_id' => $leadData['form_id'],                 'field_data' => json_encode($leadData['field_data'], JSON_UNESCAPED_UNICODE),                 'last_processed_time' => $currentDateTime,             ]);     } catch (\Exception $e) {         echo "Data entry in database failed: " . $e->getMessage() ."\n";         Log::error($e->getMessage());     } } 

Then I'm saving the leads in the DB.