【问题标题】:Get Information by Curl and Api Facebook Graph通过 Curl 和 Api Facebook Graph 获取信息
【发布时间】:2018-01-19 20:13:09
【问题描述】:

我编写此代码是为了了解有关广告公司的信息:

    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($output);" :

{“错误”:{“消息”:“无效 参数","type":"OAuthException","code":100,"error_data": {"blame_field_specs":[["account_id"]]}, "error_subcode":1885316,"is_transient":false,"error_user_title":"已禁用 帐户不能创建或编辑广告", "error_user_msg":"只有有效 帐户可以创建或编辑广告。","fbtrace_id":""}}

我在代码中的错误在哪里?请告诉我。谢谢!

【问题讨论】:

  • 看起来不像是代码问题,而只是您在那里使用的广告帐户的问题......
  • 我改变了这个: $graph_url="graph.facebook.com/v2.10/insights" 并得到新的异常:不支持的发布请求。请阅读 Graph API 文档...
  • 是的,如果您只是随意更改内容并且没有任何逻辑,就会发生这种情况......这个请求绝对没有任何意义,因为您需要先指定一个对象,然后才能访问任何见解.
  • 您是否使用了正确的 API 密钥和机密以及访问令牌?
  • 我用于测试ID 6070056173732,令牌EAAHxQfI1uiIBAEcAqSMhQPE51ZCwVgItvdTfcqiBPI1LUxUINAl7zR0pRqbKaDwZCDfHvSHJZBV1P2avk2unjgwvfk57aREf74rQS1udtKUX2ps2zTGy6Au2yGTKuOrgLcRQ4L2ZBV48Xq73RIwD43PxtXkODzDNZB4LqBScMWwZDZD,但不是API 跨度>

标签: php facebook-graph-api curl ads


【解决方案1】:

curl 也有同样的问题。在尝试了不同的方法之后,到目前为止唯一没有令牌错误或错误请求的解决方案是使用 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-23
    • 1970-01-01
    相关资源
    最近更新 更多