Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 660321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:08:35+00:00 2026-05-13T23:08:35+00:00

I’m writing a script to output Google Analytics API data and insert it into

  • 0

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.

gaFeedData.php?y[]=2009&y[]=2010&m[]=1&m[]=2

However, when I have the following string in the URL, I get an error: Fatal error: Cannot use string offset as an array in gaFeedData.php on line 56

(the m[]=8 is interchangeable with m[]=9. For whatever reason, m[]=10, m[]=11 and m[]=12 work.)

gaFeedData.php?y[]=2009&y[]=2010&m[]=8

Also note, that GA does have data for those months.

My PHP code follows, with authentication information left out:

_config.php:

<?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';

?>

gaFeedData.php:

<?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.'&ids='.$TABLE_ID.'&start-date='.$month[$mm][dfirst].'&end-date='.$month[$mm][dlast].'&metrics=ga:visits,ga:visitors,ga:pageviews,ga:timeOnSite'.'&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].", ";
    }
}

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T23:08:35+00:00Added an answer on May 13, 2026 at 11:08 pm

    You need to put your two-digit month names into quotes:

    $month["07"][dfirst]  = $yy.'-07-01';
    

    otherwise, PHP will interpret the number as an octal value:

    Formally, the structure for integer literals is: 
    
    decimal     : [1-9][0-9]*
                | 0
    
    hexadecimal : 0[xX][0-9a-fA-F]+
    
    octal       : 0[0-7]+
    ...
    

    I assume that in declaring the array members the way you do, the octal notation will lead to the wrong keys being set.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 381k
  • Answers 381k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer First things first, you need a handler on your admin… May 14, 2026 at 10:11 pm
  • Editorial Team
    Editorial Team added an answer This should work: values.FindLast(x => amount >= x.Value); May 14, 2026 at 10:11 pm
  • Editorial Team
    Editorial Team added an answer Have you tried checking Process.Id and one of the Exit… May 14, 2026 at 10:11 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.