11

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.

user2720797
  • 111
  • 1
  • 1
  • 4

2 Answers2

19

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

bjeavons
  • 1,123
  • 6
  • 16
  • do you know if the user-id is the one that you get packed inside the accessToken you get when you request permissions... i'm trying that, getting 803. https://graph.facebook.com/v3.3/165682874473626&access_token=EA.... – user1709076 Jun 27 '19 at 10:50
4

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
Mohammad Zaid Pathan
  • 16,304
  • 7
  • 99
  • 130