Google - App Engine - 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
目录中。该文件 returns 第 149 行出现错误:
if (! mkdir($storageDir, 0755, true)) {
错误是:
Warning: mkdir(): The local filesystem is readonly, mkdir failed in C:\Users\NoName\Documents\academic-being-90217\google-api-php-client\src\Google\Cache\File.php on line 149
我正在本地计算机上 运行 从 Google App Engine Launcher 测试代码。
显然,我的本地文件系统不允许 PHP 创建目录。如何允许 PHP 创建目录?我正在使用 windows 7.
在 PHP 文档中,它指出:
Note:
mode is ignored on Windows.
在Client.php文件中,Google_Client
class有一个方法isAppEngine()
。作为测试,我 运行 该方法(从我的计算机本地)并且它没有返回任何内容。所以, 。 . .在我的计算机上,测试 App Engine 项目时,google-api-php-客户端未检测到这是针对 App Engine 的。如果在 App Engine 上是 运行,当创建 $config
对象时,它会检查代码在 App Engine 上是否是 运行,并且
// Automatically use Memcache if we're in AppEngine.
if ($this->isAppEngine()) {
// Automatically use Memcache if we're in AppEngine.
$config->setCacheClass('Google_Cache_Memcache');
}
所以,我想知道代码尝试在我的计算机上创建新目录的原因是否是将其用于缓存,因为它没有检测到代码是 运行在应用引擎上。 (事实并非如此)
我想我可以将开发项目部署到 App Engine,并使用 echo 语句测试 OAuth2 功能。每次我想测试时,我都需要不断地进行部署。如果 OAuth 正常工作,显然我不需要更改任何内容。但是,如果我无法授权 OAuth2,我将如何在我的机器上本地测试新版本?
我将以下代码部署到 App Engine,并 运行 来自服务器的代码。它没有向浏览器显示错误。然后我刷新 window,并从 IF
检查中得到一条消息,表明服务令牌已设置。所以,看起来它正在授权我的应用程序作为服务。所以,我假设因为我 运行 来自 App Engine 的代码,它使用 Mem 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 不支持动态创建目录。
有点像。您只需将目录路径添加到文件名中,它就会有一个新的长文件名,但它会完成同样的事情,假设您将代码分支到环境
google-api-php-客户端库有一个名为 File.php
的文件,该文件位于 src/Google/Cache
目录中。该文件 returns 第 149 行出现错误:
if (! mkdir($storageDir, 0755, true)) {
错误是:
Warning: mkdir(): The local filesystem is readonly, mkdir failed in C:\Users\NoName\Documents\academic-being-90217\google-api-php-client\src\Google\Cache\File.php on line 149
我正在本地计算机上 运行 从 Google App Engine Launcher 测试代码。
显然,我的本地文件系统不允许 PHP 创建目录。如何允许 PHP 创建目录?我正在使用 windows 7.
在 PHP 文档中,它指出:
Note: mode is ignored on Windows.
在Client.php文件中,Google_Client
class有一个方法isAppEngine()
。作为测试,我 运行 该方法(从我的计算机本地)并且它没有返回任何内容。所以, 。 . .在我的计算机上,测试 App Engine 项目时,google-api-php-客户端未检测到这是针对 App Engine 的。如果在 App Engine 上是 运行,当创建 $config
对象时,它会检查代码在 App Engine 上是否是 运行,并且
// Automatically use Memcache if we're in AppEngine.
if ($this->isAppEngine()) {
// Automatically use Memcache if we're in AppEngine.
$config->setCacheClass('Google_Cache_Memcache');
}
所以,我想知道代码尝试在我的计算机上创建新目录的原因是否是将其用于缓存,因为它没有检测到代码是 运行在应用引擎上。 (事实并非如此)
我想我可以将开发项目部署到 App Engine,并使用 echo 语句测试 OAuth2 功能。每次我想测试时,我都需要不断地进行部署。如果 OAuth 正常工作,显然我不需要更改任何内容。但是,如果我无法授权 OAuth2,我将如何在我的机器上本地测试新版本?
我将以下代码部署到 App Engine,并 运行 来自服务器的代码。它没有向浏览器显示错误。然后我刷新 window,并从 IF
检查中得到一条消息,表明服务令牌已设置。所以,看起来它正在授权我的应用程序作为服务。所以,我假设因为我 运行 来自 App Engine 的代码,它使用 Mem 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 不支持动态创建目录。
有点像。您只需将目录路径添加到文件名中,它就会有一个新的长文件名,但它会完成同样的事情,假设您将代码分支到环境