Facebook营销API和广告洞察访问
我正在构建一个小程序,它与各种API一起工作,以自动化我们为一些客户提供的报告服务 我们报道的内容之一是Facebook广告的表现 我一直在使用Facebook营销API和Ads Insight API构建这个程序 我已经完成了建立Facebook“应用程序”和获取相关应用程序代币的整个过程 然而,由于开发访问只允许5个广告帐户,我遇到了麻烦 为了申请基本访问权限,营销API要求开发平台和一大堆与我的程序无关的东西。我不是在构建一个传统意义上的公开发布的“应用程序”;相反,我只想在基本级别上与这些API集成,以自动化一些内部任务 对我来说,这似乎令人难以置信,我不能做这样的事情,但这正是Facebook文档所暗示的Facebook营销API和广告洞察访问,facebook,facebook-ads-api,facebook-marketing-api,Facebook,Facebook Ads Api,Facebook Marketing Api,我正在构建一个小程序,它与各种API一起工作,以自动化我们为一些客户提供的报告服务 我们报道的内容之一是Facebook广告的表现 我一直在使用Facebook营销API和Ads Insight API构建这个程序 我已经完成了建立Facebook“应用程序”和获取相关应用程序代币的整个过程 然而,由于开发访问只允许5个广告帐户,我遇到了麻烦 为了申请基本访问权限,营销API要求开发平台和一大堆与我的程序无关的东西。我不是在构建一个传统意义上的公开发布的“应用程序”;相反,我只想在基本级别上与这
如果其他人熟悉此类问题,我很想知道是否有解决方法。Derks,我目前正在为40多个客户构建仪表板,我能够以基本的开发级别显示每个客户及其洞察数据等。我有代码,若你们想看一看的话,我现在唯一想做的就是做一个日期范围选择器,但是,你们非常欢迎来看看我刚刚得到的一个大概的想法 以下是来自Facebook的使用对象
<?php
require_once __DIR__ . '/vendor/autoload.php';
use FacebookAds\Api;
use FacebookAds\Object\AdUser;
use Facebook\Facebook;
use Facebook\Exceptions\FacebookResponseException;
use Facebook\Exceptions\FacebookSDKException;
use FacebookAds\Object\Campaign;
use FacebookAds\Object\Fields\AdsInsightsFields;
use FacebookAds\Object\Ad;
use FacebookAds\Object\Fields\AdSetFields;
use FacebookAds\Object\AdCampaign;
use FacebookAds\Object\Fields\AdFields;
use FacebookAds\Object\Fields;
use FacebookAds\Object\Fields\AdImageFields;
use FacebookAds\Object\AdAccount;
use FacebookAds\Object\AdSet;
use FacebookAds\Object\AdCreative;
use FacebookAds\Object\Fields\AdCreativeFields;
use FacebookAds\Object\Fields\AdCreativePhotoDataFields;
use FacebookAds\Object\AdCreativeLinkData;
use FacebookAds\Object\Fields\AdCreativeLinkDataFields;
use FacebookAds\Object\Fields\CampaignFields;
use FacebookAds\Object\Page;
use FacebookAds\Object\Fields\AdPreviewFields;
use FacebookAds\Object\Values\AdPreviewAdFormatValues;
use FacebookAds\Object\AdVideo;
?>
Here is the general code I am trying
<?php
// Init PHP Sessions
session_start();
$fb = new Facebook([
'app_id' => 'xxxxxxxxx',
'app_secret' => 'xxxxxxxxxxx',
]);
$helper = $fb->getRedirectLoginHelper();
if (!isset($_SESSION['enter api key here'])) {
$_SESSION['enter api key here'] = null;
}
if (!$_SESSION['enter api key here']) {
$helper = $fb->getRedirectLoginHelper();
try {
$_SESSION['enter api key here'] = (string) $helper->getAccessToken();
} catch(FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
}
if ($_SESSION['enter api key here']) {
//echo "You are logged in!";
// Initialize a new Session and instantiate an API object
Api::init(
'xxxxxxxxx', // App ID
'xxxxxxxxx', //app_secret
$_SESSION['enter api key here'] // Your user access token
);
?>
<div id="fbdata"></div> <?php
$account = new AdAccount('act_xxxxxxxxxx');
$params = array(
'date_preset'=> 'last_28d',
'thumbnail_width' => 200,
'thumbnail_height' => 150,
'level' => 'campaign',
'limit' => '15'
);
$fields = array(
AdsInsightsFields::CAMPAIGN_NAME,
AdsInsightsFields::CAMPAIGN_ID,
AdsInsightsFields::IMPRESSIONS,
AdsInsightsFields::CLICKS,
AdsInsightsFields::REACH,
AdsInsightsFields::SPEND,
AdsInsightsFields::CPM,
AdsInsightsFields::CPC,
AdsInsightsFields::ACTIONS,
);
$field = array(
AdCreativeFields::TITLE,
AdCreativeFields::THUMBNAIL_URL,
AdCreativeFields::BODY,
);
$params1 = array(
'time_range' => array(
'since' => (new \DateTime($beginDate))->format('Y-m-d'),
'until' => (new \DateTime($lastDate))->format('Y-m-d'),
),
'thumbnail_width' => 200,
'thumbnail_height' => 150,
'level' => 'ad',
'limit' => '5'
);
$adcreatives = $account->getAdCreatives($field, $params1);
?>
<table class="fbtable">
<tr>
<th>Title</th>
<th>Ad Image</th>
<th>Ad Body</th>
</tr>
<?php
foreach($adcreatives as $t2){
echo"<tr>
<td>$t2->title</td>
<td><img src='$t2->thumbnail_url'/></td>
<td>$t2->body</td>
</tr>";
}
$insights = $account->getInsights($fields, $params);?>
<table class="fbtable">
<tr>
<th>Campaign ID</th>
<th>Campaign Name</th>
<th>Impressions</th>
<th>Clicks</th>
<th>Reach</th>
<th>Spend</th>
<th>Total Actions</th>
<th>CPM</th>
<th>CPC</th>
</tr>
<?php
foreach($insights as $i) {
$impress = number_format((float)$i->impressions);
$reach = number_format((float)$i->reach);
$totalAction = number_format((float)$i->actions);
$cpc = number_format($i->cpc, 2, '.', '');
$cpm = number_format($i->cpm, 2, '.', '');
echo"<tr class='fbtable'>
<td>$i->campaign_id</td>
<td>$i->campaign_name</td>
<td>$impress</td>
<td>$i->clicks</td>
<td>$reach</td>
<td>$$i->spend</td>
<td>$totalAction</td>
<td>$$cpm</td>
<td>$$cpc</td>
</tr>";
}
}else {
$permissions = ['ads_management'];
$loginUrl = $helper->getLoginUrl('http://where you want login to be.com', $permissions);
echo '<a href="' . $loginUrl . '">Log in with Facebook</a>';
}
?>
这是我正在尝试的通用代码
标题
广告形象
广告正文
Derks,我目前正在为40多个客户构建仪表板,我能够以基本的开发级别显示他们中的每一个人及其见解数据等。我有代码,若你们想看一看的话,我现在唯一想做的就是做一个日期范围选择器,但是,你们非常欢迎来看看我刚刚得到的一个大概的想法
以下是来自Facebook的使用对象
<?php
require_once __DIR__ . '/vendor/autoload.php';
use FacebookAds\Api;
use FacebookAds\Object\AdUser;
use Facebook\Facebook;
use Facebook\Exceptions\FacebookResponseException;
use Facebook\Exceptions\FacebookSDKException;
use FacebookAds\Object\Campaign;
use FacebookAds\Object\Fields\AdsInsightsFields;
use FacebookAds\Object\Ad;
use FacebookAds\Object\Fields\AdSetFields;
use FacebookAds\Object\AdCampaign;
use FacebookAds\Object\Fields\AdFields;
use FacebookAds\Object\Fields;
use FacebookAds\Object\Fields\AdImageFields;
use FacebookAds\Object\AdAccount;
use FacebookAds\Object\AdSet;
use FacebookAds\Object\AdCreative;
use FacebookAds\Object\Fields\AdCreativeFields;
use FacebookAds\Object\Fields\AdCreativePhotoDataFields;
use FacebookAds\Object\AdCreativeLinkData;
use FacebookAds\Object\Fields\AdCreativeLinkDataFields;
use FacebookAds\Object\Fields\CampaignFields;
use FacebookAds\Object\Page;
use FacebookAds\Object\Fields\AdPreviewFields;
use FacebookAds\Object\Values\AdPreviewAdFormatValues;
use FacebookAds\Object\AdVideo;
?>
Here is the general code I am trying
<?php
// Init PHP Sessions
session_start();
$fb = new Facebook([
'app_id' => 'xxxxxxxxx',
'app_secret' => 'xxxxxxxxxxx',
]);
$helper = $fb->getRedirectLoginHelper();
if (!isset($_SESSION['enter api key here'])) {
$_SESSION['enter api key here'] = null;
}
if (!$_SESSION['enter api key here']) {
$helper = $fb->getRedirectLoginHelper();
try {
$_SESSION['enter api key here'] = (string) $helper->getAccessToken();
} catch(FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
}
if ($_SESSION['enter api key here']) {
//echo "You are logged in!";
// Initialize a new Session and instantiate an API object
Api::init(
'xxxxxxxxx', // App ID
'xxxxxxxxx', //app_secret
$_SESSION['enter api key here'] // Your user access token
);
?>
<div id="fbdata"></div> <?php
$account = new AdAccount('act_xxxxxxxxxx');
$params = array(
'date_preset'=> 'last_28d',
'thumbnail_width' => 200,
'thumbnail_height' => 150,
'level' => 'campaign',
'limit' => '15'
);
$fields = array(
AdsInsightsFields::CAMPAIGN_NAME,
AdsInsightsFields::CAMPAIGN_ID,
AdsInsightsFields::IMPRESSIONS,
AdsInsightsFields::CLICKS,
AdsInsightsFields::REACH,
AdsInsightsFields::SPEND,
AdsInsightsFields::CPM,
AdsInsightsFields::CPC,
AdsInsightsFields::ACTIONS,
);
$field = array(
AdCreativeFields::TITLE,
AdCreativeFields::THUMBNAIL_URL,
AdCreativeFields::BODY,
);
$params1 = array(
'time_range' => array(
'since' => (new \DateTime($beginDate))->format('Y-m-d'),
'until' => (new \DateTime($lastDate))->format('Y-m-d'),
),
'thumbnail_width' => 200,
'thumbnail_height' => 150,
'level' => 'ad',
'limit' => '5'
);
$adcreatives = $account->getAdCreatives($field, $params1);
?>
<table class="fbtable">
<tr>
<th>Title</th>
<th>Ad Image</th>
<th>Ad Body</th>
</tr>
<?php
foreach($adcreatives as $t2){
echo"<tr>
<td>$t2->title</td>
<td><img src='$t2->thumbnail_url'/></td>
<td>$t2->body</td>
</tr>";
}
$insights = $account->getInsights($fields, $params);?>
<table class="fbtable">
<tr>
<th>Campaign ID</th>
<th>Campaign Name</th>
<th>Impressions</th>
<th>Clicks</th>
<th>Reach</th>
<th>Spend</th>
<th>Total Actions</th>
<th>CPM</th>
<th>CPC</th>
</tr>
<?php
foreach($insights as $i) {
$impress = number_format((float)$i->impressions);
$reach = number_format((float)$i->reach);
$totalAction = number_format((float)$i->actions);
$cpc = number_format($i->cpc, 2, '.', '');
$cpm = number_format($i->cpm, 2, '.', '');
echo"<tr class='fbtable'>
<td>$i->campaign_id</td>
<td>$i->campaign_name</td>
<td>$impress</td>
<td>$i->clicks</td>
<td>$reach</td>
<td>$$i->spend</td>
<td>$totalAction</td>
<td>$$cpm</td>
<td>$$cpc</td>
</tr>";
}
}else {
$permissions = ['ads_management'];
$loginUrl = $helper->getLoginUrl('http://where you want login to be.com', $permissions);
echo '<a href="' . $loginUrl . '">Log in with Facebook</a>';
}
?>
这是我正在尝试的通用代码
标题
广告形象
广告正文
提交你的应用进行审查,以获得10个以上的广告帐户。使用网站的“平台”。选择本机或桌面应用程序;客户端中未嵌入应用程序机密。其余的大部分内容可以忽略,但你需要包括一些应用程序的屏幕截图,以及对其工作原理和功能的描述。一个真正的人会查看它,你可以在Facebook开发者组获得帮助:
您将只获得通过/失败…无评论。如果他们第一次拒绝,不要感到惊讶。不要再次提交,希望第二次得到更好的回复——他们最终会把你关在门外几天。向小组发布帮助问题。提交应用以供审查,以获得10个以上的广告帐户。使用网站的“平台”。选择本机或桌面应用程序;客户端中未嵌入应用程序机密。其余的大部分内容可以忽略,但你需要包括一些应用程序的屏幕截图,以及对其工作原理和功能的描述。一个真正的人会查看它,你可以在Facebook开发者组获得帮助:
您将只获得通过/失败…无评论。如果他们第一次拒绝,不要感到惊讶。不要再次提交,希望第二次得到更好的回复——他们最终会把你关在门外几天。向小组发布一个帮助问题。是,请回答。我很想看看那个代码!如果有人能帮你挑选约会范围,那也太棒了。只要问问@Derks你是否需要帮忙,我很乐意帮忙。我希望这段代码能在正确的方向上为您提供某种类型的答案。我很想看看那个代码!如果有人能帮你挑选约会范围,那也太棒了。只要问问@Derks你是否需要帮忙,我很乐意帮忙。我希望这段代码能在正确的方向上为您提供某种类型的答案。我能只包含代码的截图吗?“应用程序”甚至没有专用的GUI;我正在运行的只是一个Python脚本。如果他们第一次拒绝我,我只是运气不好吗?描述一下应用程序和它的功能,以及你的脚本输出是什么——CSV文件?展示一个小样本。你越多地告诉他们FB数据是如何公开的,他们就越有可能批准。特别是,告诉他们它是否写入任何端点,以及您正在做什么来防止速率限制和进行错误处理。他们需要对你是一个优秀的API用户感到满意。我会只包括代码的截图吗?“应用程序”甚至没有专用的GUI;我正在运行的只是一个Python脚本。如果他们第一次拒绝我,我只是运气不好吗?描述一下应用程序和它的功能,以及你的脚本输出是什么——CSV文件?展示一个小样本。你越多地告诉他们FB数据是如何公开的,他们就越有可能批准。特别是,告诉他们它是否写入任何端点,以及您正在做什么来防止速率限制和进行错误处理。他们需要感到舒适,因为你将是一个优秀的API用户。