Google-api-php-client: Class 'Google_Auth_AssertionCredentials' not found

Created on 11 Nov 2015  路  8Comments  路  Source: googleapis/google-api-php-client

Create new Dir

Add composer.json with

{
    "require": {
        "google/apiclient": "^2.0.0@RC"
    }
}

Run composer update - this gets v2.0.0-RC2 currently

Edit index.php

<?

require __DIR__ . '/vendor/autoload.php';


$client = new Google_Client();
$client->setApplicationName("HelloAnalytics");
$analytics = new Google_Service_Analytics($client);

// Read the generated client_secrets.p12 key.
$key = 'xxxxxxxxxxxx';
$cred = new Google_Auth_AssertionCredentials(
    'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxr@developer.gserviceaccount.com',
    array(Google_Service_Analytics::ANALYTICS_READONLY),
    $key
);

This is taken from https://developers.google.com/analytics/devguides/reporting/core/v3/quickstart/service-php

Run php index.php

    Fatal error: Class 'Google_Auth_AssertionCredentials' not found in /Users/xxxxx/tmp/index.php on line 12

I'm guessing PSR Autoload problem, or docs are wrong.

Most helpful comment

Thanks to whomever reported this issue. I just copypasta'd the Analytics Hello World and found myself in similar situations. Path forward was laid out for me in @ShelterJames's link:
https://github.com/google/google-api-php-client/blob/master/UPGRADING.md#google_auth_assertioncredentials-has-been-removed

Anyways, commenting to say that I've been working with this lib for a few years. While the auth tweaks are minimal, I'm finding that the interface has been tremendously simplified for service accounts. This is a welcome change. Thank you @google team.

All 8 comments

Google_Auth_AssertionCredentials has been removed in 2.x
The docs seem to be behind and not updated

See UPGRADING.md

@ShelterJames I've encountered several issues with 2.x since it's been released.
To prevent delay in development due to bugs, I've switched my composer back to "google/apiclient": "1.*" and all works fine

I've gone back to V1 and got some data out .... so guess issue is https://developers.google.com/analytics/devguides/reporting/core/v3/quickstart/service-php should mention it's V1 of the lib. Anyway, thanks.

You are correct that the docs are not up to date with v2, but the docs state to clone the v1-master branch of this library. How could we make this more clear?

We could put a banner in the README: "If you arrived here from developers.google.com, you should be using the v1-branch of this repo"

Ah, I see

git clone -b v1-master

Firstly, sorry if I was a bit harsh. Stupid day yesterday.

I think the reason I missed that the first time is that I was looking for composer setup. I'd seen the Github repo and knew this was an option, so grabbed the version from there. So things I would do:

1) I think the only place https://developers.google.com/analytics/devguides/reporting/core/v3/quickstart/service-php mentions this is in the git command, which I missed as I didn't read the command in detail. I would put a sentence is Step 2 of that page, something like "Note this tutorial applies to V1 of the library - please make sure you check that out from branch v1-master".

2) Ideally, section 2 should mention Composer setup and again be very clear in pointing out to use the version string "1.*". This would involve changing

require_once 'google-api-php-client/src/Google/autoload.php';

in section 3 to have require statements for both composer and direct download, something like:

// If you downloaded directly .... 
require_once 'google-api-php-client/src/Google/autoload.php';
// If you downloaded with composer ....
require_once 'vendor/autoload.php';

with maybe a line at the top saying "Use whichever 'require_once' statement matches your method of download, and remove the other one."

3) The composer setup section in https://github.com/google/google-api-php-client/blob/master/README.md could mention both versions, something like:

composer require google/apiclient:^2.0.0@RC
Note the documentation at developers.google.com refers to V1 of this library. If you want to use the older version, instead use:
composer require google/apiclient:1.*

Thanks,
James

Thanks to whomever reported this issue. I just copypasta'd the Analytics Hello World and found myself in similar situations. Path forward was laid out for me in @ShelterJames's link:
https://github.com/google/google-api-php-client/blob/master/UPGRADING.md#google_auth_assertioncredentials-has-been-removed

Anyways, commenting to say that I've been working with this lib for a few years. While the auth tweaks are minimal, I'm finding that the interface has been tremendously simplified for service accounts. This is a welcome change. Thank you @google team.

Thank you for y our feedback @buley!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

artemiusgreat picture artemiusgreat  路  3Comments

AlexandreGerault picture AlexandreGerault  路  5Comments

cmcfadden picture cmcfadden  路  5Comments

Romain picture Romain  路  4Comments

upendtu picture upendtu  路  4Comments