我正在做一个项目,我必须使用PHP制作服务器到服务器应用程序。
这个概念是:公司将账单上传到谷歌驱动器,用户使用该网站检索他们的账单。首先,我没有在服务器上使用作曲家,因为我没有安装权限。所以我libs
用ftp下载并上传到服务器。然后我创建了一个G Suite Google account
并按照他们的指南https://developers.google.com/api-client-library/php/auth/service-accounts中的说明进行操作。
奇怪的是 if var_dump
(service) after $results = $service->files
,我看到客户端的验证已经完成。当我尝试使用带有$results = $service->files->listFiles($optParams);
页面的 api 时没有响应。我真的很困惑。
<?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);