google-api-php-client库有一个名为File.php
的文件,该文件位于src/Google/Cache
目录中。该文件从第149行返回错误:
if (! mkdir($storageDir, 0755, true)) {
错误是:
警告:mkdir():本地文件系统是只读的,mkdir在C:\ Users \ NoName \ Documents \ academic-being-90217 \ google-api-php-client \ src \ Google \ Cache \ File.php中失败第149行
我正在通过在我的本地计算机上从Google App Engine Launcher运行代码来测试代码。
显然,我的本地文件系统不允许PHP创建目录。如何让PHP创建目录?我正在使用Windows 7。
在PHP文档中,它声明:
注意: 在Windows上忽略模式。
在 Client.php 文件中,Google_Client
类的方法为isAppEngine()
。作为测试,我运行该方法(从我的计算机本地),它什么也没有返回。所以,。 。 。在我的计算机上,测试一个App Engine项目,google-api-php-client没有检测到这是用于App Engine的。如果它在App Engine上运行,则在创建$config
对象时,它会检查代码是否在App Engine上运行,并且
//如果我们在AppEngine中,则自动使用Memcache。
if ($this->isAppEngine()) {
// Automatically use Memcache if we're in AppEngine.
$config->setCacheClass('Google_Cache_Memcache');
}
所以,我想知道代码是否试图在我的计算机上创建一个新目录的原因是将它用于Cache,因为它没有检测到代码在App Engine上运行。 (事实并非如此)
我想我可以将开发项目部署到App Engine,并使用echo语句测试OAuth2功能。每次我想测试时,我都需要不断进行部署。如果OAuth正在运行,显然我不需要改变任何东西。但是,如果我无法授权OAuth2,我将如何在我的机器上本地测试新版本?
我将以下代码部署到App Engine,并从服务器运行代码。它没有向浏览器显示错误。然后我刷新了窗口,并从IF
检查中获得了一个msg,表明已经设置了服务令牌。所以,看起来它正在授权我的应用程序作为服务。所以,我假设因为我从App Engine运行代码,它使用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';
?>
答案 0 :(得分:2)
App Engine不支持动态创建目录。
答案 1 :(得分:1)
它有点像。你只需将你的目录路径添加到文件名中,它有一个新的长文件名,但它完成了同样的事情,让你向后兼容每个文件系统类型的文件系统的旧版max文件,假设你为环境分支你的代码