简体   繁体   English

通过Curl和Api Facebook图形获取信息

[英]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);" “后续代码var_dump($输出);” :

{"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":""}} {“错误”:{“消息”:“无效参数”,“类型”:“ OAuthException”,“代码”:100,“错误数据”:{“ blame_field_specs”:[[“ account_id”]]},“错误子代码” :1885316,“ is_transient”:false,“ error_user_title”:“禁用的帐户无法创建或修改广告”,“ error_user_msg”:“只有活动帐户才能创建或修改广告。”,“ 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: 在尝试了不同的方式之后,到目前为止唯一的解决方案是我们的令牌错误或错误请求,它使用的是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 在vToken中,它是您的访问令牌,类似于$app_id . "|" . $app_secret $app_id . "|" . $app_secret

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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