简体   繁体   中英

Missing Target Audience Location Error when creating AdSet in Facebook Marketing API

I'm using the NodeJS SDK to create Campaigns, upload creatives and then create AdSet and Ads.

While creating an AdSet, I run into issues configuring my Targeting object.

Consider the following:

  const targeting = new Targeting();
  targeting[Targeting.Fields.countries] = ['US'];
  targeting[Targeting.Fields.country] = 'US';

When using this targeting for my adSet, I get the following error:

"name": "FacebookRequestError",
  "message": "Missing Target Audience Location: Your audience is missing a location. You can add a location or a Custom Audience.",
  "status": 400,
  "response": {
    "error": {
      "message": "Invalid parameter",
      "type": "OAuthException",
      "code": 100,
      "error_data": {
        "blame_field_specs": [
          [
            "targeting"
          ]
        ]
      },
      "error_subcode": 1885364,
      "is_transient": false,
      "error_user_title": "Missing Target Audience Location",
      "error_user_msg": "Your audience is missing a location. You can add a location or a Custom Audience.",
    }
  },

If I try to fill out the field geo_locations this way:

targeting[Targeting.Fields.geo_locations] = { countries: ['US'] };

I get the following error:

"name": "FacebookRequestError",
  "message": "Invalid Targeting Spec: The specified targeting spec is not valid because: The field _data is not a valid target spec field",
  "status": 400,
  "response": {
    "error": {
      "message": "Invalid parameter",
      "type": "OAuthException",
      "code": 100,
      "error_data": "null",
      "error_subcode": 1487079,
      "is_transient": false,
      "error_user_title": "Invalid Targeting Spec",
      "error_user_msg": "The specified targeting spec is not valid because: The field _data is not a valid target spec field",
    }
  },

I don't understand after reading the doc, the source code and examples on the internet how I'm supposed to fix this and properly set the Targeting for this AdSet

I realised that the documentation on the Targeting and AdSet objects relationship is wrong. It says here to create a Targeting object and pass it to the AdSet object for the PHP and JAVA SDKs, like this for example

$adset->setData(array(
  AdSetFields::NAME => 'My AdSet',
  AdSetFields::TARGETING => (new Targeting())->setData(array(
    TargetingFields::GEO_LOCATIONS => array(
      'countries' => array(
        'US',
      ),
    ),
  )),
));

I was able to solve the issue by simply doing this instead of using the SDK provided class Targeting

  const targeting = {
    geo_locations: {
      countries: ['US'],
    },
  };

  const adSet = new AdSet(accountId);
  adSet[AdSet.Fields.targeting] = targeting;
  adSet[AdSet.Fields.name] = 'Test Ad Set';

Either the documentation should have a NodeJS example or the SDK is broken and should be fixed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM