Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get FB Ad Account Id via API?

With new facebook ads API. How do I find all the ad account ID's associated with a user?

I see all the documentation about how to get details about an Account (given id). But I can not find how to get a User's ad account id (via api) https://developers.facebook.com/docs/marketing-api/adaccount/v2.3

Please advise.

like image 629
user2720797 Avatar asked Apr 06 '15 07:04

user2720797


Video Answer


2 Answers

This has helped me and I hope will help someone else too one day.

These are the steps to achieve campaign list after oAuth.

Step 1 (Front-end):

Do authentication frontend side with following URL:

https://www.facebook.com/v3.0/dialog/oauth?client_id=<client_id>&redirect_uri=<URL>&scope=email%2Cads_management%2Cads_read&response_type=code&state=<state>

Step 2 (Front-end + Backend):

Step 1 will give code object, pass it to backend

Step 3 (Backend):

Fetch access-token of user using following API

https://graph.facebook.com/v10.0/oauth/access_token?client_id=<client_id>&redirect_uri=<redirect_URL>&client_secret=<client_secret>&code=<code-from-front-end>

Step 4 (Backend):

Fetch Ads account details:

https://graph.facebook.com/v10.0/me/adaccounts?access_token=<access_token_from_step_3>

Step 5 (Backend):

Fetch Campaigns list:

https://graph.facebook.com/v10.0/act_<account_id_from_step_4>/campaigns?access_token=<access_token>&fields=id,name,objective,configured_status,effective_status,account_id,bid_amount,bid_strategy,start_time,end_time,targeting,daily_budget,campaign_id,special_ad_categories

Here you will get Campaign list of authorized user.

Note:

  • If your facebook app is under development mode then make sure you added authenticating user in your Admin/Developer/Tester list
  • Make sure authenticating account is having Campaigns
like image 181
Mohammad Zaid Pathan Avatar answered Sep 27 '22 18:09

Mohammad Zaid Pathan


Hit the /me/adaccounts path to retrieve accounts your access token (and app) can read.

See the Edges section of the user Graph API documentation for the adaccounts edge: https://developers.facebook.com/docs/graph-api/reference/user

like image 28
bjeavons Avatar answered Sep 27 '22 17:09

bjeavons