通过facebook ads api将自定义受众群体数据发送到Facebook

时间:2016-09-26 17:40:20

标签: php facebook facebook-graph-api

我有一个电子邮件ID和手机号码列表。我想将这些内容发送到Facebook,以获得相似的定位和排除某些配置文件。

我之前曾参与过图形API,并知道它是如何工作的。

阅读完文档及其实施过程后,我发现需要将https://github.com/facebook/facebook-php-ads-sdk复制到我的网站并将内容添加到https://github.com/facebook/facebook-php-ads-sdk/blob/master/examples/custom_audiences.php文件中。文件内容:

define('SDK_DIR', __DIR__ . '/..'); // Path to the SDK directory
$loader = include SDK_DIR.'/vendor/autoload.php';
use FacebookAds\Api;
Api::init($app_id, $app_secret, $access_token);
// use the namespace for Custom Audiences and Fields
use FacebookAds\Object\CustomAudience;
use FacebookAds\Object\Fields\CustomAudienceFields;
use FacebookAds\Object\Values\CustomAudienceTypes;
use FacebookAds\Object\Values\CustomAudienceSubtypes;
// Create a custom audience object, setting the parent to be the account id
$audience = new CustomAudience(null, $account_id);
$audience->setData(array(
  CustomAudienceFields::NAME => 'My Custom Audiece',
  CustomAudienceFields::DESCRIPTION => 'Lots of people',
  CustomAudienceFields::SUBTYPE => CustomAudienceSubtypes::CUSTOM,
));
// Create the audience
$audience->create();
echo "Audience ID: " . $audience->id."\n";
// Assuming you have an array of emails:
// NOTE: The SDK will hash (SHA-2) your data before submitting
// it to Facebook servers
$emails = getAllEmails();
$audience->addUsers($emails, CustomAudienceTypes::EMAIL);
$audience->read(array(CustomAudienceFields::APPROXIMATE_COUNT));
echo "Estimated Size:"
  . $audience->{CustomAudienceFields::APPROXIMATE_COUNT}."\n";
  1. 由于我下载了该文件,$loader = include SDK_DIR.'/vendor/autoload.php'; 是什么意思?

  2. 如何测试上述代码?

  3. 如果使用电子邮件和移动设备定位到相同的个人资料ID,会发生什么?

0 个答案:

没有答案