如何配置app.yaml以在app引擎上加载google-api-php-client? [英] How to configure app.yaml to load google-api-php-client on app engine?

查看:213
本文介绍了如何配置app.yaml以在app引擎上加载google-api-php-client?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图让google api php客户端在app引擎上工作。在阅读文档提供的app.yaml配置资源之后,我仍然无法使其工作。我的app.yaml具有google-api-php-client,如下所示:

   -  url:/ google-api-php -client /(.*?)/(.*?)/(.*)
script:google-api-php-client / \ 3 / \ 2 / \\\ 1.php

而且,该文件夹的结构为:

  google-api-php-client->(some_folders) - >(some_folders + files) - >(some_files)
| level1 | | level2 | | level3 | | level4 |

我想要设置配置,以便能够访问级别3中的文件和级别4,并能够像这些require_once调用:

  require_once('/ google-api-php-client / SRC / Google_Client.php'); 
require_once('/google-api-php-client/src/contrib/Google_DriveService.php');

我可以在localhost上执行这些require_once调用,但不能在将文件部署到应用程序引擎时执行。

  PHP致命错误:require_once():无法打开所需的'/ google-api- php-client / src / Google_Client.php'(include_path ='。; / base / data / home / apps / s〜... 

我会感激任何和所有输入
谢谢!

编辑:我将代码添加到'm使用require_once
$ b

  require_once('google-api-php-client / src / Google_Client.php') ; 
require_once('google-api-php-client / src / contrib / Google_DriveService.php');
session_start();

$ client = new Google_Client();
$ client-> setApplicationName(Drive Demo);
$ client-> setClientId('****');
$ client-> setClientSecret('** **');
$ client-> setRedirectUri('http:// localhost:8080');
$ client-> setDeveloperKey('****');
$ client-> setScopes(array(
'https://www.googleapis.com/auth/drive',
'https:// w ww.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/userinfo.profile'));
$ client-> setAccessType('offline');
$ service = new Google_DriveService($ client);
$ fileId ='****';

函数printFile($ service,$ fileId){
try {
$ file = $ service-> files-> get($ fileId);
print_r($ file);
打印标题:。 $文件 - >的getTitle();
print描述:。 $文件 - > getDescription();
打印MIME类型:。 $文件 - > getMimeType();
} catch(Exception $ e){
print发生错误:。 $ E->的getMessage();



函数retrieveAllFiles($ service){
$ result = array();
$ pageToken = NULL;

do {
try {
$ parameters = array('q'=>'','maxResults'=>'25','fields'=> '项目(标题,描述,mime类型)');
if($ pageToken){
$ parameters ['pageToken'] = $ pageToken;
}
$ files = $ service-> files-> listFiles($ parameters);

$ result = array_merge($ result,$ files-> getItems());
$ pageToken = $ files-> getNextPageToken();
} catch(Exception $ e){
print发生错误:。 $ E->的getMessage();
$ pageToken = NULL;
}
} while($ pageToken);
返回$ result;

$ b $ if(!isset($ _ REQUEST ['code'])&&!isset($ _ SESSION ['access_token'])){
$ authUrl = $客户端 - > createAuthUrl();
print(< a href ='。$ authUrl。'>授权我< / a>);
} else {
if(isset($ _ GET ['code'])){
$ client-> authenticate($ _ GET ['code']);
$ _SESSION ['access_token'] = $ client-> getAccessToken();


if(isset($ _ SESSION ['access_token'])){
$ client-> setAccessToken($ _ SESSION ['access_token']);

if($ client-> getAccessToken()){
$ _SESSION ['access_token'] = $ client-> getAccessToken();

}

$ files = retrieveAllFiles($ service);
foreach($ files as $ file){
// print_r($ file);
打印标题:。 $文件 - >的getTitle()。<峰; br />;
print描述:。 $文件 - > getDescription()。<峰; br />;
打印MIME类型:。 $文件 - > getMimeType()。<峰; br />;
}

}

更新:根据@ Stuart的评论删除了'/',这解决了问题。在这种情况下,您不需要配置app.yaml - 因为您不想将任何请求直接路由到这些脚本。



只需将源代码google-api-php-client与您的应用程序位于同一目录中,并使用appcfg.py进行部署。

查看我的关于配置客户端的文章这里


I have been trying to get the google api php client to work on app engine. After reading the app.yaml configuration resources provided by the documentation, I have still not been able to get this to work. My app.yaml has the google-api-php-client as it follows:

- url: /google-api-php-client/(.*?)/(.*?)/(.*)
  script: google-api-php-client/\3/\2/\1.php

And, the structure of the folder is:

google-api-php-client->(some_folders)->(some_folders+files)->(some_files)
|      level1       |  |   level2   |  |       level3     |  |  level4  |

I would like to have the configuration set so that I would be able to access the files in level 3 and level 4 and be able to do require_once calls just like these:

require_once ('/google-api-php-client/src/Google_Client.php');
require_once ('/google-api-php-client/src/contrib/Google_DriveService.php');

I am able to do these require_once calls on localhost but not when I deploy the files to app engine. The logs on app engine dashboard show this:

PHP Fatal error: require_once(): Failed opening required '/google-api-php-client/src/Google_Client.php' (include_path='.;/base/data/home/apps/s~...

I would appreciate any and all input. Thanks!

EDIT: I am adding the code where I'm using require_once

require_once ('google-api-php-client/src/Google_Client.php');
require_once ('google-api-php-client/src/contrib/Google_DriveService.php');
session_start();

$client = new Google_Client();
$client->setApplicationName("Drive Demo");
$client->setClientId('****');
$client->setClientSecret('****');
$client->setRedirectUri('http://localhost:8080');
$client->setDeveloperKey('****');
$client->setScopes(array(
  'https://www.googleapis.com/auth/drive',
  'https://www.googleapis.com/auth/userinfo.email',
  'https://www.googleapis.com/auth/userinfo.profile'));
$client->setAccessType('offline');
$service = new Google_DriveService($client);
$fileId = '****';

function printFile($service, $fileId) {
  try {
    $file = $service->files->get($fileId);
    print_r($file);
    print "Title: " . $file->getTitle();
    print "Description: " . $file->getDescription();
    print "MIME type: " . $file->getMimeType();
  } catch (Exception $e) {
    print "An error occurred: " . $e->getMessage();
  }
}

function retrieveAllFiles($service) {
  $result = array();
  $pageToken = NULL;

  do {
    try {
      $parameters = array('q'=>'', 'maxResults'=> '25', 'fields'=>'items(title,description,mimeType)');
      if ($pageToken) {
        $parameters['pageToken'] = $pageToken;
      }
      $files = $service->files->listFiles($parameters);

      $result = array_merge($result, $files->getItems());
      $pageToken = $files->getNextPageToken();
    } catch (Exception $e) {
      print "An error occurred: " . $e->getMessage();
      $pageToken = NULL;
    }
  } while ($pageToken);
  return $result;
}

if (!isset($_REQUEST['code']) && !isset($_SESSION['access_token'])) {
    $authUrl = $client->createAuthUrl();
    print("<a href='".$authUrl."'>Authorize me</a>");
}else {
    if (isset($_GET['code'])) {
      $client->authenticate($_GET['code']);
      $_SESSION['access_token'] = $client->getAccessToken();
    }

    if (isset($_SESSION['access_token'])) {
      $client->setAccessToken($_SESSION['access_token']);
    }
    if ($client->getAccessToken()) {
      $_SESSION['access_token'] = $client->getAccessToken();  

    } 

    $files = retrieveAllFiles($service);
    foreach($files as $file){
        //print_r($file);
        print "Title: " . $file->getTitle().'<br/>';
        print "Description: " . $file->getDescription().'<br/>';
        print "MIME type: " . $file->getMimeType().'<br/>';
    }

}   

Update: Removed the '/' as per @Stuart's comment, which solved the issue.

解决方案

You don't need to configure app.yaml in this case - as you don't want to route any requests directly to these scripts.

Just put the source code for google-api-php-client in the same directory as your app and deploy it using appcfg.py.

Check my article on configuring the client here.

这篇关于如何配置app.yaml以在app引擎上加载google-api-php-client?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆