【问题标题】:Server-to-Server App using Google Drive not responses to APIs calls使用 Google Drive 的服务器到服务器应用程序不响应 API 调用
【发布时间】: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


【解决方案1】:

解决了。问题是PHP版本。我切换到 7.2 并且似乎工作正常!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-10-04
    • 2013-04-04
    • 2012-04-09
    • 1970-01-01
    • 2016-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多