CCC
CCC

Reputation: 2761

authentication Facebook ad api

I need to create a Java app that stores ad names from a business account in a DB on a daily basis.

These are the steps taken:
-I was added to a business on Facebook with access to their ad accounts
-I registered an app on developers.facebook.com. -Got the access token from https://developers.facebook.com/tools/debug/accesstoken/ - Got the app secret from the the apps panel

This is the code snippet:

 public static final String ACCESS_TOKEN = [the token from above];
 public static final Long ACCOUNT_ID = [the business account it];
 public static final String APP_SECRET = [the scret from 
 public static void main(String...args) throws Exception {
            APIContext context = new APIContext(ACCESS_TOKEN, APP_SECRET);
            AdAccount account = new AdAccount(ACCOUNT_ID, context);    
System.out.println(account.getAds().execute().getRawResponseAsJsonObject());
        }

I get the following error:

com.facebook.ads.sdk.APIException$FailedRequestException: {"error":{"message":"(#273) This Ads API call requires the user to be admin of the ad account. User is not admin on ad account XXXXXXXX.","type":"OAuthException","code":273,"fbtrace_id":"GD30f+ON/k4"}}

I have the following questions:

1-Why do I need admin permission just to list the same ads I can see from the Ad Manager page?
2-What if my user losses access to the business account, but I want the Java to still function? Can other users still run the the Java code?
3-Is there anything wrong from the description and code above?
4-How can I generate a permanent token rather than a temporary one?

Upvotes: 1

Views: 629

Answers (1)

ddnomad
ddnomad

Reputation: 373

I'm a bit late with my answer, but I've encountered the same problem with Facebook Ads SDK for Python. I've investigated the cause of the issue and it seems to be connected to "tiers" a.k.a. access levelsof Facebook apps.

By default all the apps created have "development" access level which has a lot of limitations regarding programmatic access to ad accounts that you don't have an admin access to. The following quote from Access and Authentication page of Marketing API docs explains it pretty straightforward (account limits, development access level entry in a table):

Up to 5 accounts in the account list associated with your app. API calls from app admins or developers and on behalf of ad account admins or advertisers.

Basic access level:

25 ad accounts, defined by the account list associated with your app.

Standard access level:

Manage unlimited ad accounts with Marketing API app

Summing up the above quotes, you have to get standard access level for your app to be able to fully programmatically access data of any ads account without any restrictions.

The same link above explains how you can get the standard access for your app (and it involves performance assurance and review by Facebook staff.

To address your questions exactly:

  1. Just explained above
  2. It can be solved if you implement Facebook login in your app and get standard access. Then any user can login with an app and grant it necessary permissions (at least ads_management one). See corresponding docs
  3. I'm not a Java programmer but as you get APIException it just means that you got the code right though you didn't get the access levels concept so API endpoint refuses to process your request
  4. Personally have not dealt with this yet but check out this SO question

Hope I was not too late and my explanation would help you.

Upvotes: 2

Related Questions