我正在使用Facebook Marketing API(v6.0)并试图获取我拥有的每个广告集的花费,实际上我已经开始使用Graph API资源管理器,但是我发现没有什么叫做花费和花费作为字段,所以过了一会儿我得到了实际上返回错误数据的技巧,所以等式如下所示:daily_budget-budget_remaining = amount_spent,所以我们假设我们有900-800 =在业务经理中,我的应用程序返回了100 50,这是我的端点api
public function facebookData()
{
$fb = new \Facebook\Facebook([
'app_id' => 'xxxxx',
'app_secret' => 'xxxxxxx',
'default_graph_version' => 'v6.0',
//'default_access_token' => '{access-token}', // optional
]);
try {
// Returns a `FacebookFacebookResponse` object
$response = $fb->get(
'/act_xxxxxx/?fields=business,adsets.limit(1000){name,budget_remaining,daily_budget}',
'my_accesstoken'
);
} catch(FacebookExceptionsFacebookResponseException $e) {
echo 'Graph return=<i></i>ed an error: ' . $e->getMessage();
exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
$data = $response->getGraphObject()->getProperty('adsets');
try
{
foreach ($data as $ad) {
\App\FacebookAd::UpdateOrCreate([
'ad_id' => $ad['id'],
],[
'name' => $ad['name'],
'budget_remaining' => substr($ad['budget_remaining'],0,-2),
'daily_budget' => substr($ad['daily_budget'],0,-2),
'total' => substr($ad['daily_budget'],0,-2) - substr($ad['budget_remaining'],0,-2), // remove last two zeros
'account_id' => "unset",
]);
}
}
catch(\Exception $e)
{
Log::error($e->getMessage());
}
}
答案 0 :(得分:1)
尝试使用见解。 https://developers.facebook.com/docs/marketing-api/reference/ads-insights/
在您的链接中,添加下一个“见解{支出}”。因此它将给出: '/act_xxxxxx/?fields=business,adsets.limit(1000){name,insights{spend}}'