google-api-php-client: Uncaught exception 'Google_Cache_Exception' with message 'Could not create storage directory
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.
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 15 (6 by maintainers)
Commits related to this issue
- fixes #574 - checks for cachedir trailing slash — committed to bshaffer/google-api-php-client by bshaffer 9 years ago
- fixes #574 - checks for cachedir trailing slash — committed to bshaffer/google-api-php-client by bshaffer 9 years ago
- Merge pull request #753 from bshaffer/issue-574 fixes #574 - checks for cachedir trailing slash — committed to googleapis/google-api-php-client by bshaffer 9 years ago
// 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);