How to add user to facebook custom audience

丶灬走出姿态 提交于 2019-12-02 03:30:44

问题


I am trying to add user to custom audience using following code

$audience = new CustomAudience($custom_audience_id);
$audience->addUsers(array(trim($mailAddress)), CustomAudienceTypes::EMAIL);

and

$users = array(
 array('fname', 'lname', 'someone@example.com'),
 array('fnamenew', 'lnamenew', 'someone_new@example.com'),
);

$schema = array(
  CustomAudienceMultikeySchemaFields::FIRST_NAME,
  CustomAudienceMultikeySchemaFields::LAST_NAME,
  CustomAudienceMultikeySchemaFields::EMAIL,
);

$audience = new CustomAudienceMultiKey(<CUSTOM_AUDIENCE_ID>);

$audience->addUsers($users, $schema);

But I am getting error in both codes

(#2650) Failed to update the custom audience: This audience was created from data source EVENT_BASED.WEB_PIXEL_HITS, which does not support data source FILE_IMPORTED.HASHES_OR_USER_IDS

Following code I am using to create custom audience.

$audience = new CustomAudience(null, $accountId);
        $audience->setData(array(
          CustomAudienceFields::NAME            => $associative_arr['name'],
          CustomAudienceFields::PIXEL_ID        => $associative_arr['pixelId'],
          CustomAudienceFields::DESCRIPTION     => $associative_arr['description'],
          CustomAudienceFields::RETENTION_DAYS  => $associative_arr['retensionDays'],  
          CustomAudienceFields::SUBTYPE         => CustomAudienceSubtypes::WEBSITE,
          CustomAudienceFields::RULE            => array('url' => array('i_contains' => $associative_arr['websiteUrl'])),
          CustomAudienceFields::PREFILL         => $associative_arr['prefill'],
          CustomAudienceFields::DATA_SOURCE     => array('EVENT_BASED' => 'WEB_PIXEL_HITS')
        ));         
        $audience->create();

Any suggestion how I can solve this?


回答1:


You can only add user to the custom audience that is created through emails, While the code you shown in creating audience is based on user activities on your website. You can follow this doc to create your custom audience through email: https://developers.facebook.com/docs/marketing-api/audiences-api#build

And then in your ads, you can combine the two audience (From emails and/ from



来源:https://stackoverflow.com/questions/40483537/how-to-add-user-to-facebook-custom-audience

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!