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

google-api-php-client-2.0.0 #988

Closed
ashik906 opened this Issue Jul 13, 2016 · 11 comments

Comments

Projects
None yet
4 participants
@ashik906
Copy link

ashik906 commented Jul 13, 2016

Hello @bshaffer

i integrate google analytic dashboard on my admin

Deprecated: google-api-php-client's autoloader was moved to vendor/autoload.php in 2.0.0. This redirect will be removed in 2.1. Please adjust your code to use the new location. in /var/www/html/example.com/analiytics/google-api-php-client-2.0.0/src/Google/autoload.php on line 19

Fatal error: Uncaught exception 'InvalidArgumentException' with message 'file does not exist' in /var/www/html/example.com/analiytics/google-api-php-client-2.0.0/src/Google/Client.php:839 Stack trace: #0 /var/www/html/example.com/analiytics/google-api-php-client-2.0.0/src/Google/Client.php(824): Google_Client->setAuthConfig('client_secrets....') #1 /var/www/html/example.com/analiytics/index.php(13): Google_Client->setAuthConfigFile('client_secrets....') #2 {main} thrown in /var/www/html/example.com/analiytics/google-api-php-client-2.0.0/src/Google/Client.php on line 839

Above error get

@bshaffer

This comment has been minimized.

Copy link
Contributor

bshaffer commented Jul 14, 2016

Verify your setAuthConfig file exists. You should always supply the absolute path to your credentials file, i.e:

$credentialsFile = '/full/path/to/myfile.json';
$client->setAuthConfig($credentialsFile);

@bshaffer bshaffer closed this Jul 14, 2016

@ashik906

This comment has been minimized.

Copy link
Author

ashik906 commented Jul 15, 2016

Hello @bshaffer

I given full path for credentialsfile

$credentialsFile = '/var/www/html/example.com/analiytics/client_secrets.json';
$client->setAuthConfig($credentialsFile);

This error genrate

Deprecated: google-api-php-client's autoloader was moved to vendor/autoload.php in 2.0.0. This redirect will be removed in 2.1. Please adjust your code to use the new location. in /var/www/html/example.com/analiytics/google-api-php-client-2.0.0/src/Google/autoload.php on line 19

and also every time link redirect to google authentication url after show data

Deprecated: google-api-php-client's autoloader was moved to vendor/autoload.php in 2.0.0. This redirect will be removed in 2.1. Please adjust your code to use the new location. in /var/www/html/example.com/analiytics/google-api-php-client-2.0.0/src/Google/autoload.php on line 19

First view (profile) found: All Web Site Data

Total sessions: 50

Total Pageviews: 124

Total User: 27

Thankyou

@bshaffer

This comment has been minimized.

Copy link
Contributor

bshaffer commented Jul 15, 2016

The error states the use of the file src/Google/autoload.php is deprecated, and instead you need to use vendor/autoload.php. If you follow what the error states, and update all includes to the new file location, the error will be resolved. i.e:

// what you have now:
require_once '/path/to/google-api-php-client/src/Google/autoload.php';
// what you should update it to:
require_once '/path/to/google-api-php-client/vendor/autoload.php';

@bshaffer bshaffer reopened this Jul 15, 2016

@bshaffer bshaffer closed this Jul 15, 2016

@nmartin4321

This comment has been minimized.

Copy link

nmartin4321 commented Jul 25, 2016

@bshaffer I ditto the above and even after updating the path to: require_once '/path/to/google-api-php-client/vendor/autoload.php'; while I no longer get

Deprecated: google-api-php-client's autoloader was moved.. >

I still get a set of errors similar to @ashik906 :

Fatal error: Uncaught exception 'InvalidArgumentException' with message 'file does not exist' in /var/www/html/example.com/analiytics/google-api-php-client-2.0.0/src/Google/Client.php:839 Stack trace: #0 /var/www/html/example.com/analiytics/google-api-php-client-2.0.0/src/Google/Client.php(824): Google_Client->setAuthConfig('client_secrets....') #1 /var/www/html/example.com/analiytics/index.php(13): Google_Client->setAuthConfigFile('client_secrets....') #2 {main} thrown in /var/www/html/example.com/analiytics/google-api-php-client-2.0.0/src/Google/Client.php on line 839

@bshaffer

This comment has been minimized.

Copy link
Contributor

bshaffer commented Jul 25, 2016

@nmartin4321 You need to either download the package and dependencies found in the releases section, or install via composer

@nmartin4321

This comment has been minimized.

Copy link

nmartin4321 commented Jul 25, 2016

Thanks @bshaffer , apologies I should have set some context. I followed all instructions here: https://developers.google.com/analytics/devguides/reporting/core/v3/quickstart/web-php
Using Windows 7 (IIS 7+ with IIS Express PHP v 7)
Installed Composer & verified all dependencies are in place.

In 'Client.php' the referenced line suggests that there's something wrong with the information being passed for the Auth config:
public function setAuthConfig($config) { if (is_string($config)) { if (!file_exists($config)) { throw new InvalidArgumentException('file does not exist'); } ...

Some more googling suggested that I use json_decode() in my index.php and oauth2callback.php fields for the 'client_secrets.json'. I did this and it seems to move beyond the error I posted earlier but still throws an odd error where it spits out hundreds of lines showing the same thing:
[Mon Jul 25 15:02:33 2016] PHP Deprecated: google-api-php-client's autoloader was moved to vendor/autoload.php in 2.0.0. This redirect will be removed in 2.1. Please adjust your code to use the new location. in C:\Users\XXXXXX\vendor\google\apiclient\src\Google\autoload.php on line 20

Now the problem is, I have also confirmed that all my references to the autoload.php in question are updated. (as "C:\Users\XXXXXX" is doc root, I've equivalents of $file = '/vendor/autoload.php'; in each location)

So, I'm still not sure the the json_decode() effort actually helped. Making no other changes, if I revert my json_decode() update, I get back to the original error. Any thoughts?

@bshaffer

This comment has been minimized.

Copy link
Contributor

bshaffer commented Jul 25, 2016

Make sure your call to setAuthConfig is an absolute path and that you've renamed the file you download from the Developer Console to client_secrets.json. :

$client->setAuthConfig('/path/to/client_secrets.json');

You do not need to use json_decode, and the deprecated error is being thrown as a result of an error in your local development setup, and not because of this library.

@bshaffer

This comment has been minimized.

Copy link
Contributor

bshaffer commented Jul 25, 2016

One of the reasons you're having a hard time is you're using the v3 samples, which are older and outdated. Try using the Analytics v4 quickstart instead.

@nmartin4321

This comment has been minimized.

Copy link

nmartin4321 commented Jul 25, 2016

@bshaffer this is perfect, thank you! applying the path seemed to do the trick (I'd assumed since all the files were in the same directory that it'd pick it up if I just left it with the file name.)

Also, thanks for the pointer on v4. If I encounter further issues, I'll move there.

Again, thank you! U R Legend!

@ashik906

This comment has been minimized.

Copy link
Author

ashik906 commented Sep 19, 2016

Hello @bshaffer,

we are using Google Analytics API in PHP project. But when i connect with API it gives error..
Please visit this link
http://www.4lifesystem.com/analiytics/analytic.php

Error:
Catchable fatal error: Argument 3 passed to Google_AuthHandler_Guzzle6AuthHandler::attachCredentials() must be callable, string given, called in /var/www/html/4lifesystem.com/analiytics/google-api-php-client-2.0.0/src/Google/Client.php on line 370 and defined in /var/www/html/4lifesystem.com/analiytics/google-api-php-client-2.0.0/src/Google/AuthHandler/Guzzle6AuthHandler.php on line 30


Here is my code


setApplicationName("lifesystem"); $client->setAuthConfig($KEY_FILE_LOCATION); $client->setScopes('https://www.googleapis.com/auth/analytics.readonly'); $analytics = new Google_Service_Analytics($client); return $analytics; } function getFirstProfileId($analytics) { // Get the user's first view (profile) ID. // Get the list of accounts for the authorized user. $accounts = $analytics->management_accounts->listManagementAccounts(); if (count($accounts->getItems()) > 0) { $items = $accounts->getItems(); $firstAccountId = $items[0]->getId(); // Get the list of properties for the authorized user. $properties = $analytics->management_webproperties ->listManagementWebproperties($firstAccountId); if (count($properties->getItems()) > 0) { $items = $properties->getItems(); $firstPropertyId = $items[0]->getId(); // Get the list of views (profiles) for the authorized user. $profiles = $analytics->management_profiles ->listManagementProfiles($firstAccountId, $firstPropertyId); if (count($profiles->getItems()) > 0) { $items = $profiles->getItems(); ``` // Return the first view (profile) ID. return $items[0]->getId(); ``` } else { throw new Exception('No views (profiles) found for this user.'); } } else { throw new Exception('No properties found for this user.'); } } else { throw new Exception('No accounts found for this user.'); } } function getResults($analytics, $profileId) { // Calls the Core Reporting API and queries for the number of sessions // for the last seven days. $profileId=79768194; return $analytics->data_ga->get( 'ga:' . $profileId, '7daysAgo', 'today', 'ga:sessions'); } function printResults($results) { // Parses the response from the Core Reporting API and prints // the profile name and total sessions. if (count($results->getRows()) > 0) { // Get the profile name. $profileName = $results->getProfileInfo()->getProfileName(); // Get the entry for the first entry in the first row. $rows = $results->getRows(); $sessions = $rows[0][0]; // Print the results. print "First view (profile) found: $profileName\n"; print "Total sessions: $sessions\n"; } else { print "No results found.\n"; } }
@abhishekroy007

This comment has been minimized.

Copy link

abhishekroy007 commented Sep 11, 2018

I've done everything you have suggested "#988" here but still getting this error.

Fatal error: Uncaught InvalidArgumentException: file does not exist in D:\xampp\htdocs\Google\vendor\google\apiclient\src\Google\Client.php:839 Stack trace: #0 D:\xampp\htdocs\Google\HelloAnalytics.php(23): Google_Client->setAuthConfig('D:\xampp\htdocs...') #1 D:\xampp\htdocs\Google\HelloAnalytics.php(6): initializeAnalytics() #2 {main} thrown in D:\xampp\htdocs\Google\vendor\google\apiclient\src\Google\Client.php on line 839

I have the credentials file at the correct location and has set the location correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.