Paul Grenyer
Paul Grenyer

Reputation: 1853

Using Facebook Ads API and Spring Social Facebook

I'm developing a SpringBoot application which needs to manage multiple Facebook Ad accounts. I've successfully used the Facebook Java Ads SDK:

https://github.com/facebook/facebook-java-ads-sdk

to connect to a single Facebook ads account, via a Facebook app within the same account (account A) and create a campaign and query campaigns, ads sets, etc:

public static final APIContext context = new APIContext(ACCESS_TOKEN, APP_SECRET);

    public static void main(String[] args)
    {
        try
        {
            AdAccount account = new AdAccount(ACCOUNT_ID, context);
            Campaign campaign = account.createCampaign().setName("Java SDK Test Campaign")
                    .setObjective(Campaign.EnumObjective.VALUE_LINK_CLICKS).setSpendCap(10000L)
                    .setStatus(Campaign.EnumStatus.VALUE_PAUSED).execute();
            System.out.println(campaign.fetch());
        } catch (APIException e)
        {
            e.printStackTrace();
        }
    }

Thew ACCESS_TOKEN, APP_SECRET and ACCOUNT_ID are all from the same Facebook account (account A), the one in which the Facebook app was created. The Facebook app has the ads_management permissions reviewed and approved.

Now I need to be able to access Facebook Ad Accounts from other Facebook accounts. I've used the spring-social-facebook Accessing Facebook Data tutorial:

https://spring.io/guides/gs/accessing-facebook/

To register a different Facebook account (account B) with the Facebook App, using the scopes "ads_read, ads_management" and the account ID for the new Facebook account (account B) was added to the Facebook App from the original account (account A).

However, when I used the second account's account ID in the code above I get:

 {"error":{"message":"Unsupported get request. Object with ID 'act_105428933326149' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https:\/\/developers.facebook.com\/docs\/graph-api","type":"GraphMethodException","code":100,"fbtrace_id":"Ee5exTqJdCp"}

Which suggests I have a permissions issue somewhere, but I'm stumped. I'm not even sure I'm following the correct approach.

I've tried googling for an example of how to use the Facebook Ads API with spring-social-facebook, but other than a few commits to the repository which don't help a great deal, I can't find one.

Upvotes: 0

Views: 965

Answers (1)

Jiaming
Jiaming

Reputation: 121

Facebook Ads API has tiered access. A newly registered app is in Development Tier and can only access the user's own ad accounts. You need to meet certain criteria to get promoted to Basic Tier and manage other people's ad account.

Upvotes: 0

Related Questions