我正在构建一个小程序,它与各种API一起工作,以自动化我们为一些客户提供的报告服务。
我们报道的其中一件事是Facebook的广告表现。
我一直在使用Facebook营销应用编程接口和广告洞察API https://developers.facebook.com/docs/marketing-apis构建这个程序。
我已经完成了设置Facebook“应用程序”并获取相关应用程序令牌的整个过程。
然而,我遇到了障碍,因为开发访问只允许5个广告帐户。
为了申请基本访问权限,营销API要求提供开发平台和一大堆与我的程序无关的其他东西。我不是在构建一个传统意义上的公开发布的“应用程序”;相反,我只是想在基础层面上集成这些app,以自动化一些内部任务。
对我来说,我不能做这样的事情似乎令人难以置信,但这就是Facebook文档似乎所暗示的。
如果其他人熟悉这类问题,我很想知道是否有解决方法。
发布于 2017-06-27 19:19:40
Derks,我目前正在与40多个客户建立仪表板,我能够显示他们中的每个人和他们的洞察数据等与基本的开发水平。我有代码,如果你想看一看,我现在唯一想要完成的事情是做一个日期范围选择器,但是,你足够受欢迎,看看我有什么只是为了得到一个大致的想法。
下面是来自Facebook的Use对象
<?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,我相信你唯一需要做的就是找出程序的方法,或者无论你的建筑知道谁是谁。
发布于 2017-06-29 02:06:38
提交您的应用程序进行审查,以获得10个以上的广告帐户。使用网站的“平台”。选择本机或桌面应用程序;客户端中未嵌入应用程序密码。剩下的大部分可以忽略,但你需要包括一些你的应用程序的屏幕截图,以及它是如何工作和它做了什么的描述。真人会对其进行审核,你可以在脸书开发者小组中获得帮助:https://www.facebook.com/groups/fbdevelopers
你会得到一个通过/失败的only...no评论。如果他们第一次拒绝它,不要感到惊讶。不要重新提交,并希望第二次得到更好的答复--他们最终会把你锁在门外几天。将帮助问题发布到组中。
https://stackoverflow.com/questions/44765260
复制