How to get FB Ad Account Id via API?
Asked Answered
R

2

12

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.

Riyadh answered 6/4, 2015 at 7:40 Comment(0)
E
20

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

Exclamation answered 6/4, 2015 at 17:43 Comment(1)
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. graph.facebook.com/v3.3/165682874473626&access_token=EA....Alena
S
6

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
Sporophyll answered 11/3, 2021 at 16:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.