Facebook Graph API(将v2.10从v3.10升级)

时间:2018-12-17 09:48:58

标签: php facebook facebook-graph-api

我有一个旧的Facebook应用程序(v.2.10),用于检索广告系列结果,已停止工作。

升级到3.10以上版本后出现错误。

enter image description here

这是我的应用程序代码,比较从Graph Api工具获得的api代码是相同的。

<?php

require_once __DIR__ . '/vendor/autoload.php'; // change path as needed

$fb = new Facebook\Facebook(array(
  'app_id' => 'xxx',
  'app_secret' => 'xxxx',
  'default_graph_version' => 'v3.20',
  'default_access_token' => 'xxxxx',
 ));

try {

 $response_active = $fb->get(    'act_1646241562297916/insights?fields=ad_id,ad_name,adset_name,reach,cpc,ctr,clicks,spend&time_range={"since":"2017-01-01","until":"2020-03-31"}&filtering=[{"field":"ad.effective_status","operator":"IN","value":["ACTIVE"]}]&level=ad&limit-1'
 );


} catch(FacebookExceptionsFacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} 

$graphEdge_active = $response_active->getGraphEdge();

//Convert JSON string to Array
$myArray_active = json_decode($graphEdge_active);

?>

<table class="rnr-c rnr-cont rnr-c-grid rnr-b-grid rnr-gridtable hoverable " cellpadding="0">
  <thead>
      <tr class="rnr-toprow style1 ">
      <th class="rnr-gridfieldlabel" style="text-align: center;">ad_id</th>
      <th class="rnr-gridfieldlabel" style="text-align: center;">spend</th>
      </tr>
  </thead>
   <tbody>
 <?php 

 foreach($myArray_active as $results_active){    
          echo "<tr class=\"rnr-row style1 \" id=\"gridRow5\">";     
          echo "<td class=\"rnr-field-text\">" .$results_paused->ad_id."</td>";

          echo "<td class=\"rnr-field-text\">" .$results_active->spend."</td>"; 
          echo "</tr>";
 }

?>

0 个答案:

没有答案