Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error when creating custom audience #43

Closed
cornernote opened this issue Nov 27, 2014 · 13 comments
Closed

error when creating custom audience #43

cornernote opened this issue Nov 27, 2014 · 13 comments

Comments

@cornernote
Copy link

The code:

use \FacebookAds\Api;
use \FacebookAds\Object\CustomAudience;
use \FacebookAds\Object\Fields\CustomAudienceFields;

Api::init($app_id, $app_secret, $access_token);

$audience = new CustomAudience(null, $account_id);
$audience->setData(array(
    CustomAudienceFields::NAME => 'test',
    CustomAudienceFields::DESCRIPTION => 'test',
    CustomAudienceFields::DATA_SOURCE => array('EVENT_BASED' => 'WEB_PIXEL_HITS'),
));
$audience->create();

The error:

(#2655) Terms of service has not been accepted

I have 2 questions:

  1. How do I agree to the terms of service? When I create a custom audience through the web interface there is a checkbox each time I create one.
  2. Am I setting the DATA_SOURCE correctly? I want an audience based on hits to a single page. The code I used is based of the docs here, but there is no clear example for the specific scenario I want:
    https://developers.facebook.com/docs/reference/ads-api/custom-audience-targeting/#data_source
@paulbain
Copy link
Contributor

This is not an issue with the SDK so I'm going to close it out. You need to go to audiences in ads manager to accept the Custom Audiences terms. There is also a field within the account capabilities that indicates whether it has been accepted.
https://www.facebook.com/ads/manage/audiences.php

To create audience of people who visit your website, you'll want to use a Website Custom Audience, see this CURL example to capture all people who visit a site with a pixel on it:
https://developers.facebook.com/docs/reference/ads-api/custom-audience-website/v2.2#create

@cornernote
Copy link
Author

Hi @paulbain,

It's not an issue with the SDK, its more of an issue with the API.

I went to the web interface, created an audience, accepted the terms. My code still throws the exception:

(#2655) Terms of service has not been accepted

Would you be able to provide an example of the SDK performing the call to create a Website Custom Audience?

I appreciate all the help you have provided, and I know several of the things you are helping with are not directly SDK related.

@paulbain
Copy link
Contributor

is it accepted for the same adaccount you are using? it's per-adaccount and there is a dropdown menu at the top. I'm not sure if there is a separate one for website custom audiences. Try creating an audience in adsmanager to check for that also.

I'll put together an example later today if I can. You can also ask non-issue questions (how do I do X?) on StackOverflow as there is an active community of people helping there and the format is easier for these kinds of questions:
stackoverflow.com/questions/tagged/facebook-ads-api

@cornernote
Copy link
Author

When you create a Website Traffic Audience on facebook.com it does not ask for you to agree to the terms. You need to create a Customer List Audience, then you need to add 20 email addresses. Once this is saved I was able to add audiences using the API.

@cornernote
Copy link
Author

The code to add the audience was:

use \FacebookAds\Api;
use \FacebookAds\Object\CustomAudience;
use \FacebookAds\Object\Fields\CustomAudienceFields;

Api::init($app_id, $app_secret, $access_token);

$audience = new CustomAudience(null, $account_id);
$audience->setData(array(
    CustomAudienceFields::NAME => 'website test',
    CustomAudienceFields::DESCRIPTION => 'website test',
    CustomAudienceFields::SUBTYPE => 'WEBSITE',
    CustomAudienceFields::RETENTION_DAYS => '30',
    CustomAudienceFields::RULE => array('url' => array('contains' => '/foobar')),
));
$audience->create();

Would be great to see this in the examples.

@cornernote
Copy link
Author

The code to use the audience in an AdSet was:

use \FacebookAds\Api;
use \FacebookAds\Object\AdSet;
use \FacebookAds\Object\Fields\AdSetFields;
use \FacebookAds\Object\CustomAudience;
use \FacebookAds\Object\Fields\CustomAudienceFields;

Api::init($app_id, $app_secret, $access_token);

$audience = new CustomAudience(null, $account_id);
$audience->setData(array(
    CustomAudienceFields::NAME => 'website test',
    CustomAudienceFields::DESCRIPTION => 'website test',
    CustomAudienceFields::SUBTYPE => 'WEBSITE',
    CustomAudienceFields::RETENTION_DAYS => '30',
    CustomAudienceFields::RULE => array('url' => array('contains' => '/foobar')),
));
$audience->create();

$targeting = array(
    'custom_audiences' => array(
        array(
            'id' => $audience->{CustomAudienceFields::ID},
            'name' => $audience->{CustomAudienceFields::NAME},
        )
    )
);

// create adSet
$adSet = new AdSet(null, $account_id);
$adSet->setData(array(
    AdSetFields::NAME => 'My Ad',
    AdSetFields::CAMPAIGN_GROUP_ID => 1234567890, // replace with campaign id
    AdSetFields::CAMPAIGN_STATUS => AdSet::STATUS_ACTIVE,
    AdSetFields::DAILY_BUDGET => '100',
    AdSetFields::BID_TYPE => 'CPC',
    AdSetFields::BID_INFO => array('CLICKS' => 30),
    AdSetFields::TARGETING => $targeting,
));
$adSet->create();

@cornernote
Copy link
Author

Sorry, that didnt work...

[error] => Array (
    [message] => An unknown error has occurred.
    [type] => OAuthException
    [code] => 1
)

Error occurs on the line $adSet->create();. Do I need to give more permissions?

@cornernote
Copy link
Author

Nevermind the last message, the code does work. I messed up the targeting array when testing.

@IAmMukeshKumar
Copy link

IAmMukeshKumar commented Nov 26, 2017

I am using laravel 5.4
On executing the code to create audiences I am getting the following error.
PHP Fatal error: Uncaught FacebookAds\Http\Exception\AuthorizationException: (#2663) Terms of service has not been accepted. To accept, go to https://www.facebook.com/customaudiences/app/tos/?act=105142470269795 in /Users/williammukesh/facebook-php-ads-sdk/src/FacebookAds/Http/Exception/RequestException.php:144

After hitting:https://www.facebook.com/customaudiences/app/tos/?act=105142470269795
screen shot 2017-11-26 at 3 41 50 pm

but the below url shows I have accepted TOS.
https://www.facebook.com/customaudiences/app/tos/

@IAmMukeshKumar
Copy link

Plz tell me If you guys have any idea to fix this issue.

@bevinhex
Copy link

I'm having the same issue with nodejs sdk even now.

@Taytay
Copy link

Taytay commented Jun 21, 2018

If you are using a sandbox, you need to follow these steps (grabbed from this StackOverflow answer: https://stackoverflow.com/a/42766604/544130):
"To accept custom audiences ToS go to the application management -> Marketing API -> Tools -> Sandbox Ad Account Management -> Actions -> Accept TOS"

@sonhgc00016
Copy link

@Taytay I have already Accept TOS like the step you describe but I still facing error when using sandbox. Do you solve the problem?

{
  "error": {
    "message": "Permissions error",
    "type": "OAuthException",
    "code": 200,
    "error_subcode": 1870034,
    "is_transient": false,
    "error_user_title": "Custom Audience Terms Not Accepted",
    "error_user_msg": "You'll need to agree to the Custom Audience terms before you can create or edit an audience of CUSTOM type. To accept, go to https://www.facebook.com/ads/manage/customaudiences/tos/?act=313575366050779.",
    "fbtrace_id": "CQhFmQpzyoS"
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants