facebook / facebook-php-business-sdk

PHP SDK for Meta Marketing API
https://developers.facebook.com/docs/business-sdk
Other
836 stars 519 forks source link

help with FacebookPermissionException #17

Closed cornernote closed 10 years ago

cornernote commented 10 years ago

Hello,

I am getting this error:

Facebook\FacebookPermissionException (#294) Managing advertisements requires the extended permission ads_management and an application that is whitelisted to access the Ads API

I'm not sure what to try or who to contact. Any help would be greatly appreciated.

phzhou commented 10 years ago

Hi, did you include the ads_management permission when getting the the access token? Please refer to the authentication guide here: https://developers.facebook.com/docs/reference/ads-api/overview#access_token

paulbain commented 10 years ago

Also, please make sure your application has been whitelisted for access to the Facebook Ads API

cornernote commented 10 years ago

Thanks for responding.

@phzhou, no I had not done that. But it seems it didn't help.

I did the following:

1) get the AUTHORIZATION_CODE from the URL after going here: https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&scope=ads_management&redirect_uri=https://www.my.com/

2) get the $access_token from the response after going here: https://graph.facebook.com/oauth/access_token? client_id=YOUR_APP_ID&redirect_uri=YOUR_URL& client_secret=YOUR_APP_SECRET&code=AUTHORIZATION_CODE

My code looks like this:

        FacebookSession::setDefaultApplication($app_id, $app_secret);
        new Api(new FacebookSession($access_token));
        $set = new AdSet($ad_set_id);
        $set->{AdSetFields::NAME} = 'Test API Update';
        $set->update();

And I get back the exception mentioned above.

@paulbain How do I do that?

I read through this: https://developers.facebook.com/docs/preferredmarketingdevelopers/ads-api-access

It indicated I needed to complete this application form: https://www.facebook.com/help/contact/517221111658494

I did so, and was sent an approved email almost immediately.

The issue still persists.

paulbain commented 10 years ago

It may be worth reaching out to the person from whom you received the email just to check it was whitelisted correctly. Let me know your app id and I'll see if I can check also.

cornernote commented 10 years ago

The email I thought was in reply to that contact was actually not. I have since received a reply to the whitelist request and they asked for the app id, and to ensure it was not in sandbox mode. It was in fact in sandbox mode.

Although it's not approved/working yet, I think this is the problem.

Thanks for the help.

cornernote commented 10 years ago

I tried emailing adsapi@fb.com with a request to be whitelisted, however I still have not had a reply. I sent another email today and am hoping for a response.

Do you have any other suggestions regarding who I can contact to be whitelisted for ads api usage?

paulbain commented 10 years ago

we opened up access for everyone now in development mode, take a look at: https://developers.facebook.com/docs/reference/ads-api/access/v2.1

cornernote commented 10 years ago

Hi @paulbain,

I added my Ad Account IDs to the app settings (App > Settings > Advanced > Ads API).

I also noticed that when I make calls on the Account ID, a different Account ID is also added to the app's settings.

Still getting the same error: (#294) Managing advertisements requires the extended permission ads_management and an application that is whitelisted to access the Ads API

I have worked with Google Ads, Bing Ads and several others. I'm struggling to understand why FB Ad API has this barrier to entry.

Is there anyone at FB that I should contact for help, or would I be better of working with you in this thread?

Thanks for all your help so far.

paulbain commented 10 years ago

in order to access advertising components of the Graph API, you need to request the ads_management permission from the user (which is probably you in this case). The key difference FB and other platforms is that we have a single unified platform which is permissioned.

Take a look at the getting started guide to see how to handle authentication: https://developers.facebook.com/docs/reference/ads-api/overview#access_token

The best places to ask for help is either here for specific Ads API SDK issues, or StackOverflow for general technical questions and the marketing developer community on Facebook for more strategic/product questions:

http://stackoverflow.com/questions/tagged/facebook-ads-api https://www.facebook.com/groups/pmdcommunity/

It would be great to hear your feedback onboarding with the SDK and how this can be improved also. That's probably best via messenger: fb.me/paulbain

cornernote commented 10 years ago

Take a look at the getting started guide to see how to handle authentication: https://developers.facebook.com/docs/reference/ads-api/overview#access_token

I did the following:

1) get the AUTHORIZATION_CODE from the URL after going here: https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&scope=ads_management&redirect_uri=https://www.my.com/

2) get the $access_token from the response after going here: https://graph.facebook.com/oauth/access_token? client_id=YOUR_APP_ID&redirect_uri=YOUR_URL& client_secret=YOUR_APP_SECRET&code=AUTHORIZATION_CODE

3) I now have an $access_token, and I use it in the following code:

 FacebookSession::setDefaultApplication($app_id, $app_secret);
new Api(new FacebookSession($access_token));
$set = new AdSet($ad_set_id);
$set->{AdSetFields::NAME} = 'Test API Update';
$set->update();

This results in the error:

(#294) Managing advertisements requires the extended permission ads_management and an application that is whitelisted to access the Ads API

cornernote commented 10 years ago

@paulbain,

As you suggested the issue was the Grey account. I added the account to the Business Manager as you suggested: https://www.facebook.com/help/420039848100178

Seems to have got me past this error, however now I have a similar issue: (#273) This Ads API call requires the user to be admin of the ad account. User XXX not admin on ad account YYY.

Do you know how I set my user to be the admin of the ad account?

Thanks for all your help.

cornernote commented 10 years ago

Got it!

business.facebook.com > Settings > People > Assigned Ad Accounts

From here you can choose the role.