1

I'm using Google's PHP client library to access the analytics API and I keep getting an error, Call to a member function on a non-object. I've been stumped for more than a day. I've read through several solutions, and I'm not seeing how to resolve this.

require_once "google-api-php-client/src/Google_Client.php";
require_once "google-api-php-client/src/contrib/Google_AnalyticsService.php";
session_start();

$client = new Google_Client();
$client->setApplicationName("app-name");
$client->setClientId('client-id');
$client->setClientSecret('my-secret');
$client->setRedirectUri('http://www.website.com/');
$client->setDeveloperKey('secret-key');

$analyticsService = new Google_AnalyticsService($client);
$dailyUploads = $analyticsService->dailyUploads;

This is (I think) the way that Google recommends to set this up, yet when I print out the contents of $dailyUploads its empty/null. If I print out $analyticsService I see the code of Google_AnalyticsService.

Later in my code, after authentication, I attempt to use the upload function like so:

$upload = $dailyUploads->upload($media);

This produces the error that I mentioned earlier, Fatal error: Call to a member function upload() on a non-object.

Can anyone help? What am I overlooking?

1 Answer 1

2

I've now resolved this. There were two issues:

  1. The Google_AnalyticsService.php file has been updated since the most recent stable release, so the code that I linked to wasn't actually loaded in my project. I resolved this by updating my library to include the code displayed on their website.

  2. The correct way to refer to the class is 'management_dailyUploads'. I updated my code as such.

    $analyticsService = new Google_AnalyticsService($client);
    $dailyUploads = $analyticsService->management_dailyUploads;

    $upload = $dailyUploads->upload('123456', 'UA-123456-1', 'xXxXxXxX', 2013-02-15, 1, 'cost', array("reset" => true, "data" => file_get_contents('/path/to/file.csv'), "mimeType" => 'application/octet-stream', "uploadType" => 'media'));

Once I implemented these updates my app started communicating with Google's servers. I now have a different issue to solve (don't we always?), but the question that prompted this thread has been resolved so I'll mark this as answered.

ps - I don't know why the code didn't format correctly here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.