Note that there are some explanatory texts on larger screens.

plurals
  1. PO"Fatal error: Cannot use string offset as an array" when variable is 08 or 09
    primarykey
    data
    text
    <p>I'm writing a script to output Google Analytics API data and insert it into a bar chart using Google Charts API. When I have a string like this in the URL, I get the desired result.</p> <pre><code>gaFeedData.php?y[]=2009&amp;y[]=2010&amp;m[]=1&amp;m[]=2 </code></pre> <p>However, when I have the following string in the URL, I get an error: <strong>Fatal error: Cannot use string offset as an array in gaFeedData.php on line 56</strong></p> <p>(the m[]=8 is interchangeable with m[]=9. For whatever reason, m[]=10, m[]=11 and m[]=12 work.)</p> <pre><code>gaFeedData.php?y[]=2009&amp;y[]=2010&amp;m[]=8 </code></pre> <p>Also note, that GA <strong>does</strong> have data for those months.</p> <p>My PHP code follows, with authentication information left out:</p> <p><strong>_config.php:</strong></p> <pre><code>&lt;?php $accountType = 'GOOGLE'; // DONT EDIT! // Account type $source = 'report'; // DONT EDIT! // Application name $accountName = 'user@gmail.com'; // User's email $accountPass = 'password'; // User's password $clientName = 'useratgmail'; // Client's name $goalid = $_GET['goal']; $startdate = $_GET['startdate']; $enddate = $_GET['enddate']; $y[0] = 0; $m[0] = 0; $y = $_GET["y"]; $m = $_GET["m"]; $URIAuth = 'https://www.google.com/accounts/ClientLogin'; $URIFeedAcct = 'https://www.google.com/analytics/feeds/accounts/default?prettyprint=true'; $URIFeedData = 'https://www.google.com/analytics/feeds/data?prettyprint=true'; ?&gt; </code></pre> <p><strong>gaFeedData.php:</strong></p> <pre><code>&lt;?php include("_config.php"); $TABLE_ID = 'ga:11111111'; foreach ($y as $yy) { if ($yy%400==0) $leapyear='1'; elseif ($yy%100== 0) $leapyear='0'; elseif ($yy%4==0) $leapyear='1'; else $leapyear='0'; $month = array(); $month[01][dfirst] = $yy.'-01-01'; $month[01][dlast] = $yy.'-01-31'; $month[02][dfirst] = $yy.'-02-01'; if ($leapyear=='1') $month[02][dlast] = $yy.'-02-29'; else $month[02][dlast] = $yy.'-02-28'; $month[03][dfirst] = $yy.'-03-01'; $month[03][dlast] = $yy.'-03-31'; $month[04][dfirst] = $yy.'-04-01'; $month[04][dlast] = $yy.'-04-30'; $month[05][dfirst] = $yy.'-05-01'; $month[05][dlast] = $yy.'-05-31'; $month[06][dfirst] = $yy.'-06-01'; $month[06][dlast] = $yy.'-06-30'; $month[07][dfirst] = $yy.'-07-01'; $month[07][dlast] = $yy.'-07-31'; $month[08][dfirst] = $yy.'-08-01'; $month[08][dlast] = $yy.'-08-31'; $month[09][dfirst] = $yy.'-09-01'; $month[09][dlast] = $yy.'-09-30'; $month[10][dfirst] = $yy.'-10-01'; $month[10][dlast] = $yy.'-10-31'; $month[11][dfirst] = $yy.'-11-01'; $month[11][dlast] = $yy.'-11-30'; $month[12][dfirst] = $yy.'-12-01'; $month[12][dlast] = $yy.'-12-31'; foreach ($m as $mm) { sleep(0.2); $ch = curl_init($URIFeedData.'&amp;ids='.$TABLE_ID.'&amp;start-date='.$month[$mm][dfirst].'&amp;end-date='.$month[$mm][dlast].'&amp;metrics=ga:visits,ga:visitors,ga:pageviews,ga:timeOnSite'.'&amp;alt=json'); $fp = fopen("$clientName.data.feed", "w"); $accountAuth = exec('awk /Auth=.*/ '.$clientName.'.auth'); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: GoogleLogin $accountAuth","GData-Version: 2")); curl_exec($ch); curl_close($ch); fclose($fp); $jsonfile = fopen("$clientName.data.feed", "r"); $jsondata = fread($jsonfile, filesize("$clientName.data.feed")); $output = json_decode($jsondata, 512); $data[$yy][$mm][visits] = $output[feed]["dxp\$aggregates"]["dxp\$metric"][0][value]; echo $data[$yy][$mm][visits].", "; } } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload