I'm getting the following error while trying the example on https://developers.google.com/analytics/devguides/reporting/core/v3/quickstart/service-php with the latest code:
Warning: mkdir(): Permission denied in /mnt/web1/e0/53/44455566/htdocs/myApp123/admin/google-api-php-client-master/src/Google/Cache/File.php on line 149 Fatal error: Uncaught exception 'Google_Cache_Exception' with message 'Could not create storage directory: /var/tmp//Google_Client/d7' in /mnt/web1/e0/53/44455566/htdocs/myApp123/admin/google-api-php-client-master/src/Google/Cache/File.php:154 Stack trace: #0 /mnt/web1/e0/53/44455566/htdocs/myApp123/admin/google-api-php-client-master/src/Google/Cache/File.php(139): Google_Cache_File->getCacheDir('306ab5989d4665e...', true) #1 /mnt/web1/e0/53/44455566/htdocs/myApp123/admin/google-api-php-client-master/src/Google/Cache/File.php(134): Google_Cache_File->getCacheFile('306ab5989d4665e...', true) #2 /mnt/web1/e0/53/44455566/htdocs/myApp123/admin/google-api-php-client-master/src/Google/Cache/File.php(95): Google_Cache_File->getWriteableCacheFile('306ab5989d4665e...') #3 /mnt/web1/e0/53/44455566/htdocs/myApp123/admin/google-api-php-client-master/src/Google/Auth/OAuth2.php(315): Google_Cache_File->set('306ab5989d4665e...', '{"access_token"...') #4 /mnt/web1/e0/53/44455566/htdocs/myApp123/admin/HelloAnalytics.php(31): Google_Auth_O in /mnt/web1/e0/53/44455566/htdocs/myApp123/admin/google-api-php-client-master/src/Google/Cache/File.php on line 154
After investigation I found the issue in file "google-api-php-client-master/src/Google/Cache/File.php" in function "getCacheDir($file, $forWrite)". The storage directory is created like:
$storageDir = $this->path . '/' . substr(md5($file), 0, 2);
But the error in my case is the concatenated slash after the path. It already contains a slash! Refer to error message:
/var/tmp//Google_Client/d7'
After the "tmp" folder there are 2 slashes now that raises the error. If I remove the concatenation of this slash, it works fine.
Is that path being generated automatically, or have you set it in the config?
I didn't set the path by myself. I'm even not allowed to do changes for that. I only can use it because the scripts are running at a big webhosting company.
Yeah, I think we could probably be defensive here and check for a trailing slash before adding.
I get the same error message if I run code using this library with two different user accounts. The /tmp/google-api-php-client folder is owned by the first user who runs the code, and can't be accessed by other users.
this is strange, I would expect the permissions to be set by the web server.
If you're executing a script, just specify a cache directory with proper permissions (i.e. an an existing directory with a group permission that includes both users).
I'm running it in a CLI manner.
Also I wasn't aware you could specify the cache directory, need to RTFM a bit closer
I'm not sure it's in the manual. But yeah you can do this:
$client = new Google_Client();
$client->setCache(new Google_Cache_File('/path/to/shared/cache'));
Amazing, thanks!
Hello, I get a similar error whenI Insert Google Calendar Entries with Service Account: `Warning: mkdir(): Permission denied in /mydomain.com/app/google-api-php-client/src/Google/Cache/File.php on line 149
Fatal error: Uncaught exception 'Google_Cache_Exception' with message 'Could not create storage directory: /tmp/Google_Client/d5' in/mydomain.com/app/google-api-php-client/src/Google/Cache/File.php:154 Stack trace: #0 /mydomain.com/app/google-api-php-client/src/Google/Cache/File.php(139): Google_Cache_File->getCacheDir('5277a54f911ee9a...', true) #1 /mydomain.com/app/google-api-php-client/src/Google/Cache/File.php(134): Google_Cache_File->getCacheFile('5277a54f911ee9a...', true) #2 /mydomain.com/app/google-api-php-client/src/Google/Cache/File.php(95): Google_Cache_File->getWriteableCacheFile('5277a54f911ee9a...') #3 /mydomain.com/app/google-api-php-client/src/Google/Auth/OAuth2.php(322): Google_Cache_File->set('5277a54f911ee9a...', '{"access_token"...') #4 /mydomain.com/app/_database/db_tools.php(1361): Google_Auth_OAuth2->refreshTokenWithAssertion(Object(Google_Auth_AssertionCredentia in /mydomain.com/app/google-api-php-client/src/Google/Cache/File.php on line 154`
My code works perfectly in localhost but when I run it in my server It shows this error above.
@betollaque what version of the library are you using? I imagine this is a permissions issue, and the web server does not have permissions to write to the temp directory. Try fixing the permissions or setting the cache to something else:
$client->setCache(new Google_Cache_Memcache);
Hello! I found a solution:
Config.php
Line 143: 'directory' => '/path/to/shared/cache'
This works for me. I'm using the last stable realese 1.1.7.
Glad to hear it!
$client = new Google_Client();
$client->setClassConfig('Google_Cache_File', array('directory' => '/path/to/cache/directory'));
I'm seeing this problem. It seems to make the login fail.
// Here is how I fixed it in my own code for my Google calendar service when I moved to a different host without the need to touch Google's code.
$config = new Google_Config();
$config->setClassConfig('Google_Cache_File', array('directory' => '../tmp/cache'));
$client = new Google_Client($config);