简体   繁体   中英

Get Information by Curl and Api Facebook Graph

I wrote this code for information about ad company:

    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);
}

And call this method:

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

"var_dump($output);" :

{"error": {"message":"Invalid parameter","type":"OAuthException","code":100,"error_data": {"blame_field_specs":[["account_id"]]}, "error_subcode":1885316,"is_transient":false,"error_user_title":"Disabled accounts can't create or edit ads", "error_user_msg":"Only active accounts can create or edit ads.","fbtrace_id":""}}

Where is my mistake in the code? Tell me please. Thank you!

Same problem with curl. After trying diffrent ways the only solution so far withour token errors or bad requests it's using 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);

Where vToken it's your access token made like $app_id . "|" . $app_secret $app_id . "|" . $app_secret

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM