我正在研究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());
}
}
尝试使用见解。https://developers.facebook.com/docs/marketing-api/reference/ads-insights/
在您的链接中,添加下一个“见解{支出}”。因此它将给出:'/act_xxxxxx/?fields=business,adsets.limit(1000){name,insights{spend}}'