【发布时间】:2019-04-09 13:12:42
【问题描述】:
我正在做一个项目,我必须使用 PHP 制作服务器到服务器的应用程序。
概念是:公司将账单上传到谷歌驱动器,用户使用该网站检索他们的账单。首先,我没有在服务器上使用作曲家,因为我没有安装权限。所以我下载了libs并用ftp上传到服务器。然后我创建了一个G Suite Google account 并按照他们的指南https://developers.google.com/api-client-library/php/auth/service-accounts 中的说明进行操作。
奇怪的是如果var_dump(service) 在$results = $service->files 之后,我看到客户端的验证已经完成。当我尝试将 api 与 $results = $service->files->listFiles($optParams); 一起使用时,页面没有响应。我真的很困惑。
<?php
session_start();
require_once "vendor/autoload.php";
require 'init.php';
putenv('GOOGLE_APPLICATION_CREDENTIALS=service.json');
$client = getClient();
$service = new Google_Service_Drive($client);
function getClient() {
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
return $client;
}
$optParams = array(
'pageSize' => 5,
'fields' => 'files(webViewLink, name , parents, id)'
);
$results = $service->files->listFiles($optParams);
【问题讨论】:
-
能否提供日志?
-
[06-Nov-2018 16:21:23 UTC] PHP 解析错误:语法错误、意外的“类”(T_CLASS)、需要标识符(T_STRING)或变量(T_VARIABLE)或“{”或 /home/obiorange/public_html/nera/google-api-php-client-2.2.2/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php 第 84 行中的“$”
-
我发现出现这个错误是因为 'class' 是一个常量的名称,只有 PHP 5.5 不使用它作为标签。我的 PHP 版本是 5.6.30。
标签: php api google-drive-api server-to-server