Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class 'Google_Auth_AssertionCredentials' not found #748

Closed
ShelterJames opened this issue Nov 11, 2015 · 8 comments
Closed

Class 'Google_Auth_AssertionCredentials' not found #748

ShelterJames opened this issue Nov 11, 2015 · 8 comments
Assignees

Comments

@ShelterJames
Copy link

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.

@ShelterJames
Copy link
Author

@ascalabro
Copy link

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

See UPGRADING.md

@ascalabro
Copy link

@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

@ShelterJames
Copy link
Author

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.

@bshaffer
Copy link
Contributor

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"

@ShelterJames
Copy link
Author

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."

  1. 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

@buley
Copy link

buley commented Dec 18, 2015

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.

@bshaffer
Copy link
Contributor

bshaffer commented Jan 5, 2016

Thank you for y our feedback @buley!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants