我想转换这个Facebook Graph API请求:
act_xyz/ads?fields=insights.date_preset(yesterday){ad_name,adset_name,campaign_name,account_name,account_id,impressions,inline_link_clicks,spend,ad_id},adcreatives{object_story_spec}
使用Facebook Ads PHP SDK。现在我有了这段代码:
$account = new AdAccount('act_xyz');
$fields = array(
InsightsFields::AD_NAME,
InsightsFields::ADSET_NAME,
InsightsFields::CAMPAIGN_NAME,
InsightsFields::ACCOUNT_NAME,
InsightsFields::ACCOUNT_ID,
InsightsFields::IMPRESSIONS,
InsightsFields::INLINE_LINK_CLICKS,
InsightsFields::SPEND,
InsightsFields::AD_ID
);
$params = array(
'date_preset' => InsightsPresets::YESTERDAY
);
$account->getInsights($fields, $params);
[...]
$fields = array(
AdCreativeFields::OBJECT_STORY_SPEC
);
$account->getAdCreatives($fields);
我可以单独获取所有数据,但我希望获取AdAccount上每个广告的AdCreatives和Insights,例如Graph API。 感谢。
答案 0 :(得分:1)
如果您拥有正确的访问令牌,您仍然可以对广告相关端点执行Graph API调用。使用最新的Facebook PHP SDK& Facebook广告PHP SDK: -
$fb = new Facebook(['app_id' => {APP_ID}, 'app_secret' => {APP_SECRET}]);
$account = new AdAccount('act_xyz');
$data = $fb->get('/' . $account->id . '/ads?fields=insights.date_preset(yesterday){ad_name,adset_name,campaign_name,account_name,account_id,impressions,inline_link_clicks,spend,ad_id},adcreatives{object_story_spec}', $access_token);
我测试了这个并且它有效。我正在使用Facebook PHP SDK v5.1.2和Facebook Ads PHP SDK v2.5.1。
希望这有帮助! :d