Google-应用程序引擎-API PHP-警告:mkdir():本地文件系统是只读的,mkdir失败-允许本地文件系统


Google - App Engine - API PHP - Warning: mkdir(): The local filesystem is readonly, mkdir failed - Allow local filesystem to make directory

google api php客户端库有一个名为File.php的文件,该文件位于src/Google/Cache目录中。该文件从第149行返回一个错误:

if (! mkdir($storageDir, 0755, true)) {

错误为:

警告:mkdir():本地文件系统是只读的,mkdir在第149行的C:''Users''NoName''Documents''acaderic-being-90217''google api php client''src''google''Cache''File.php中失败

我通过在本地计算机上运行谷歌应用程序引擎启动器来测试代码。

显然,我的本地文件系统不允许PHP创建目录。如何允许PHP制作目录?我用的是Windows7。

在PHP文档中,它指出:

注:模式在Windows上被忽略。

Client.php文件中,Google_Client类有一个方法isAppEngine()。作为一个测试,我运行了这个方法(从我的计算机本地运行),它没有返回任何结果。所以在我的计算机上,在测试一个应用程序引擎项目时,googleapiphp客户端没有检测到这是针对应用程序引擎的。如果它在App Engine上运行,当创建$config对象时,它会检查代码是否在App Engine和上运行

//如果我们在AppEngine中,则自动使用Memcache。

if ($this->isAppEngine()) {
  // Automatically use Memcache if we're in AppEngine.
  $config->setCacheClass('Google_Cache_Memcache');
}

所以,我想知道代码试图在我的计算机上创建一个新目录的原因是否是将其用于缓存,因为它没有检测到代码正在应用程序引擎上运行。(事实并非如此)

我想我可以将一个开发项目部署到AppEngine,并使用echo语句测试OAuth2功能。每次我想测试时,我都需要不断地进行部署。如果OAuth正在工作,显然我不需要更改任何内容。但是,如果我不能授权OAuth2,我将如何在我的机器上本地测试新版本?

我将以下代码部署到App Engine,并从服务器上运行代码。它没有向浏览器显示错误。然后我刷新了窗口,并从IF检查中得到一条消息,表明服务令牌已经设置。所以,它看起来像是在授权我的应用程序作为一项服务。因此,我假设,因为我从应用程序引擎运行了代码,所以它使用Mem Cache,而不是创建Cache目录,并将数据保存到文件中。

<?php
session_start();
//The php file loaded below outputs information to the user in the browser
include_once "templates/base.php";
//The autoload.php file loads the entire API library I think.  It avoids needing to call specific files.
require_once realpath(dirname(__FILE__) . '/google-api-php-client/src/Google/autoload.php');
//The following three lines are the credentials
$client_id = 'my ID here.apps.googleusercontent.com'; //Client ID
$service_account_name = 'My name here@developer.gserviceaccount.com'; //Email Address
$key_file_location = 'Test Project-file-name.p12'; //key.p12
//Display a page header to the user in their browser
echo pageHeader("Service Account Access");
//Check if the credentials are present and assigned to their variable names
if (!strlen($client_id)
    || !strlen($service_account_name)
    || !strlen($key_file_location)) {
  echo missingServiceAccountDetailsWarning();
}
//The Google_Client Class is in file Client.php
//Create a Google_Client object and use it to acquire an access token
$client = new Google_Client();
/*
foreach($client as $key => $value) {
  echo $key." - ".'<br>';
}
*/
//The object $client was just created in the above line of code.  Call the function 'setApplicationName' that is inside of
//the $client object.
$client->setApplicationName("Client_Drive_Examples");
$service = new Google_Service_Drive($client);
/************************************************
  If we have an access token, we can carry on.
  Otherwise, we'll get one with the help of an
  assertion credential. In other examples the list
  of scopes was managed by the Client, but here
  we have to list them manually. We also supply
  the service account
 ************************************************/
if (isset($_SESSION['service_token'])) {
  echo 'There is a service token';
  $client->setAccessToken($_SESSION['service_token']);
}
$key = file_get_contents($key_file_location);
//echo 'the $key: ' . $key;
//echo '$service_account_name: ' . $service_account_name;
/*
https://www.googleapis.com/auth/drive - View and manage the files in your Google Drive
https://www.googleapis.com/auth/drive.file - View and manage files that you have created with this app
https://spreadsheets.google.com/feeds/ - Manage your spreadsheets
*/
$scopes = array('https://www.googleapis.com/auth/drive', 'https://www.googleapis.com/auth/drive.file');
$cred = new Google_Auth_AssertionCredentials(
    $service_account_name,
    $scopes,
    $key
);
$client->setAssertionCredentials($cred);
if ($client->getAuth()->isAccessTokenExpired()) {
  $client->getAuth()->refreshTokenWithAssertion($cred);
}

$_SESSION['service_token'] = $client->getAccessToken();
echo 'end of code';
?>

App Engine不支持动态创建目录。

它有点像tho。您只需将目录路径添加到文件名中,它就会有一个新的长文件名,但它也能实现同样的功能,使您与旧的每个文件夹类型的文件系统的最大文件数保持向后兼容,假设您将代码分支到环境