gpt4 book ai didi

php - 调用未定义的方法 Google_Service_Drive_FileList::getItems()

转载 作者:可可西里 更新时间:2023-11-01 13:38:25 24 4
gpt4 key购买 nike

我正在实现 google drive API。

我已经引用了这个谷歌文档 https://developers.google.com/api-client-library/php/auth/web-app#example .

这是我的index.php

<?php
require_once __DIR__ . '/vendor/autoload.php';

session_start();

$client = new Google_Client();
$client->setAuthConfigFile('client_secret.json');
$client->addScope(Google_Service_Drive::DRIVE_METADATA_READONLY);

if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
$client->setAccessToken($_SESSION['access_token']);
$drive_service = new Google_Service_Drive($client);
$files_list = $drive_service->files->listFiles(array())->getItems();
echo json_encode($files_list);
} else {
$redirect_uri = 'http://127.0.0.1/googleApiQuickstart/oauth2callback.php';
header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
}

还有我的 oauth2callback.php

<?php
require_once __DIR__ . '/vendor/autoload.php';

session_start();

$client = new Google_Client();
$client->setAuthConfigFile('client_secret.json');
$client->setRedirectUri('http://127.0.0.1/googleApiQuickstart/oauth2callback.php');
$client->addScope(Google_Service_Drive::DRIVE_METADATA_READONLY);

if (!isset($_GET['code'])) {
$auth_url = $client->createAuthUrl();
header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL));
} else {
$client->authenticate($_GET['code']);
$_SESSION['access_token'] = $client->getAccessToken();
$redirect_uri = 'http://127.0.0.1/googleApiQuickstart';
header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
}

但是出现错误。

Call to undefined method Google_Service_Drive_FileList::getItems()

我哪里错了?

最佳答案

$files_list = $drive_service->files->listFiles(array())->getItems();

改为->

$files_list = $drive_service->files->listFiles(array())->getFiles();

似乎 getItems(); 不再起作用你必须使用 getFiles(); 而不是 getItems();

关于php - 调用未定义的方法 Google_Service_Drive_FileList::getItems(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37975479/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com