2017-08-11 171 views
0

我寫了這個代碼信息有關的廣告公司:獲取信息

public function getStatAd($id_company, $time_range, $fields, $access_token){ 
    $curl = new Curl\Curl(); 
    $graph_url= "https://graph.facebook.com/v2.10/" . $id_company;      
    $postData = "&time_range=" . $time_range            
           . "&fields=" 
           . $fields             
           . "&access_token=" . $access_token;      

    $ch = curl_init(); 

    curl_setopt($ch, CURLOPT_URL, $graph_url); 
    curl_setopt($ch, CURLOPT_HEADER, 0); 
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 

    $output = curl_exec($ch);                

    curl_close($ch); 

    //var_dump($output); 
} 

而且調用此方法:

getStatAd(
    $_POST['id_company'], 
    "'since':2017-08-10,'until':2017-08-17", // to do dynamic 
    "reach,impressions,clicks,spend", 
    "token" 
    ); 

「的var_dump($輸出);」 :

{ 「錯誤」:{ 「消息」: 「無效 參數」, 「類型」: 「OAuthException」, 「代碼」:100, 「error_data」: { 「blame_field_specs」:[[」 「account_id」]]}, 「error_subcode」:1885316,「is_transient」:false,「error_user_title」:「已禁用 帳戶無法創建或編輯廣告」,「error_user_msg」:「只有活躍 帳戶可以創建或編輯廣告「,」fbtrace_id「:」「}}

我在代碼中的錯誤在哪裏?請告訴我。謝謝!

+0

使你的訪問令牌看起來不像一個代碼問題,而只是一個問題與您在那裏使用的廣告帳戶... – CBroe

+0

我改變這一點:$ graph_url =「https://graph.facebook.com/v2.10/insights」並獲得新的異常:不支持的發佈請求。請閱讀圖形API文檔... – Zunder

+0

是的,如果你只是不加思索地改變東西而發生這種事情......這個請求絕對沒有任何意義,因爲你需要先指定一個對象,然後才能訪問任何見解。 – CBroe

回答

0

與捲曲相同的問題。嘗試不同勢方法唯一的解決方案至今全無標記錯誤或壞的請求後,它使用的file_get_contents:

$graph_url_post = "https://graph.facebook.com/".$vPostID."?fields=full_picture,type&access_token=" . $vToken; 

$post_info = json_decode(file_get_contents($graph_url_post), true); 

哪裏vToken它就像$app_id . "|" . $app_secret