我在这里。我正在尝试使用图形API 从 facebook广告中检索线索,而不是不使用PHP Business SDK,因为这是不必要的麻烦我使用了 cURL lib 发出请求。
中提取了信息这是我的代码:
public function __construct($access_token){
$this->access_token = $access_token;
Api::init(
self::FB_APP_ID,
self::FB_APP_SECRET,
$this->access_token
);
}
public function getLeadsByAd($ad_id){
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://graph.facebook.com/v3.1/'.$ad_id.'/leads?'.'access_token='.$this->access_token
));
$leads = curl_exec($curl);
curl_close($curl);
/* #SDK Method
$ad = new Ad($ad_id);
$leads = $ad->getLeads();*/
return json_decode($leads); // should return a casted json with documentation format
}
我遇到以下错误:
{
"error" : {
"message" : "(#100) Tried accessing nonexisting field (leads) on node type (AdCampaignGroup)",
"type" : "OAuthException",
"code" : 100,
"fbtrace_id" : "ClZgY7+KlgY"
}
}
编辑1:
以下是获取广告ID的方法:
public function getActiveAds(){
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://graph.facebook.com/v3.1/act_'.self::FB_ACCOUNT_ID.'/campaigns?status=["active"]&access_token='.$this->access_token
));
$campaignSets = curl_exec($curl);
curl_close($curl);
/* SDK Method
$account = new AdAccount('act_' . self::FB_ACCOUNT_ID);
$fields = array(CampaignFields::ID,'effective_status');
$params = array(
'effective_status' => array(
Campaign::STATUS_ACTIVE
),
);
$campaignSets = $account->getCampaigns($fields, $params);
*/
return json_decode($campaignSets); // returns an array with StdClass Object ([id] => GIVEN_ID)
}