使用Google Drive API(PHP)列出文件时出错(Error listing files with Google Drive API (PHP))
我正在尝试使用Google的PHP API列出Google云端硬盘中的文件( https://developers.google.com/drive/v2/web/quickstart/php )。
我已设法获取范围访问令牌,但Google提供的列表文件示例代码( https://developers.google.com/drive/v2/reference/files/list#response )返回错误。
这是我的代码:
$client = new Google_Client(); $client->setAuthConfigFile('/usr/share/nginx/google.json'); $client->setAccessToken($a4e->user->google_token); // access token scoped for DRIVE_READONLY $drive_service = new Google_Service_Drive($client); $files=retrieveAllFiles($drive_service); var_dump($files); function retrieveAllFiles($service) { $result = array(); $pageToken = NULL; do { try { $parameters = array(); 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; }
这将返回以下错误:
致命错误:在第30行的/usr/share/nginx/html/tools/google/index.php中调用未定义的方法Google_Service_Drive_FileList :: getItems()
有谁知道我做错了什么?
提前谢谢了。
I'm trying to list files in Google Drive using Google's PHP API (https://developers.google.com/drive/v2/web/quickstart/php).
I've managed to obtain a scoped access token, but the sample code Google provides for listing files (https://developers.google.com/drive/v2/reference/files/list#response) is returning an error.
Here is my code:
$client = new Google_Client(); $client->setAuthConfigFile('/usr/share/nginx/google.json'); $client->setAccessToken($a4e->user->google_token); // access token scoped for DRIVE_READONLY $drive_service = new Google_Service_Drive($client); $files=retrieveAllFiles($drive_service); var_dump($files); function retrieveAllFiles($service) { $result = array(); $pageToken = NULL; do { try { $parameters = array(); 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; }
This returns the following error:
Fatal error: Call to undefined method Google_Service_Drive_FileList::getItems() in /usr/share/nginx/html/tools/google/index.php on line 30
Does anyone know what I'm doing wrong?
Many thanks in advance.
原文:https://stackoverflow.com/questions/37986267
最满意答案
看起来Artifactory在jcenter-cache中缓存了一个错过的检索。 如果Artifactory由于某种原因(例如超时)未能从JCenter获取junit,它将在远程存储库的“Missed Retrieval Cache Period”属性中配置的时间段内缓存此故障。
您可以清除此项并强制Artifactory尝试通过切换缓存来再次检索工件。适用于这种情况:
转到工件>工件资源库浏览器> jcenter-cache> junit / junit> 4.12
或者只需点击
HTTP://我-自己的服务器:8081 / artifactory的/ web应用/#/神器/浏览/树/一般/ jcenter缓存/ JUnit的/ JUnit的/ 4.12
右键单击4.12> Zap Cache:
Looks like Artifactory have a missed retrieval cached in the jcenter-cache. If Artifactory failed to get junit from JCenter for some reason (for example a timeout) it will cache this failure for the period configured in the "Missed Retrieval Cache Period" property of the remote repository.
You can clear this and force Artifactory to try and retrieve the artifact again by zapping the cache.Applied for this situation:
Go to Artifacts > Artifact Repository Browser > jcenter-cache > junit/junit > 4.12
or just click on
Right click on 4.12 > Zap Cache:
相关问答
更多-
junit 4.12 before什么意思[2023-09-02]
@Before 在每个测试方法之前都会运行一次,需声明成public 使用示例: public class Example { List empty; @Before public void initialize() { empty= new ArrayList(); } @Test public void size() { ... } @Test public void remove() { ... } } -
看起来Artifactory在jcenter-cache中缓存了一个错过的检索。 如果Artifactory由于某种原因(例如超时)未能从JCenter获取junit,它将在远程存储库的“Missed Retrieval Cache Period”属性中配置的时间段内缓存此故障。 您可以清除此项并强制Artifactory尝试通过切换缓存来再次检索工件。 适用于这种情况: 转到工件>工件资源库浏览器> jcenter-cache> junit / junit> 4.12 或者只需点击 HTTP://我-自己 ...
-
我找到了答案。 我的POM正在使用Mule运行时3.8.3
3.8.3 但是,没有与此版本对应的json模块的发行版。 Mulesoft Releases的最新Mulesoft Releases是3.8.1: https://repository.mulesoft.org/nexus/content/repositories/releases/org/mule/modules/mule-module-json/3.8.1/ 因此,在我的POM中手动 ... -
特别 根据关于http://www.joptimizer.com/usage.html的Building笔记: JOptimizer基于maven 3.0构建。 在构建它之前,必须解决(在pom.xml中)Colt和其他不在公共存储库中的依赖关系的外部依赖关系。 请参阅“依赖”报告以获得完整的治疗。 为了便于使用,提供了一个与这些外部库绑定的界面 (请参阅“下载”):提取文件夹中的界限并运行“maven-install.cmd”(用您自己的shell语言翻译),您将获得本地存储库中的工件。 要获得此包,请转 ...
-
该错误是由于无法加载测试类引起的。 您是否将包mypackage.tests.controller(即包含类文件或jar存档的文件夹)放在junit调用的类路径中? 这可以使用嵌套的类路径结构来完成。 (http://ant.apache.org/manual/Tasks/junit.html)。 The error is caused by the fact that your test classes cannot be loaded. Did you put the package mypackage ...
-
更新junit会在@Rule和TestName处出现编译错误(Updating junit gives compilation error at @Rule and TestName)[2023-06-22]
从版本4.12迁移到4.5感觉更像是降级而不是更新。 @Rule是在4.7版本的junit中引入的,因此无法找到。 现在最稳定的junit版本是4.12 ,至少这是你可以在maven资源库中找到的最新版本 。 但是, junit5是在7.7.2016中引入的,如果应用此依赖项,则可以使用它:org.junit junit5-api 5.0.0-SNAPSHO ... -
找不到类Java JUnit(Could not find class Java JUnit)[2022-06-02]
java -classpath lib/junit.jar;classes org.junit.runner.JUnitCore ua.edu.sumdu.j2se.savchenko.pr2.tests.TaskTest java -classpath lib/junit.jar;classes org.junit.runner.JUnitCore ua.edu.sumdu.j2se.savchenko.pr2.tests.TaskTest -
MyTest是否真的在默认包中? 如果不是,那么你需要给出整个包的限定名。 换句话说,如果MyClass有一个声明 package com.myself; 并住进去 /myproject/src/com/myself/MyClass.java 你编译成 /myproject/classes 那么/myproject/classes必须位于您的CLASSPATH ,您必须 java org.junit.runner.JUnitCore com.myself.MyTest 想想看,现在我看到你将.cla ...
-
似乎版本2.4不在中央,而是在“jboss第三方”存储库中。 如果您为此repo添加配置,它应该可以工作。 有几种方法可以做到这一点,具体取决于您是否使用了回购管理器。 您可以在settings.xml中或在要构建的项目的pom.xml中指定它。 使用mvnrepository.com时,请务必注意显示pom标记的选项卡上方表中的Repositories字段。 It appears that version 2.4 is not in central, but is in the "jboss 3rd-pa ...
-
你的pom列出了JUnit 3.81但是那个版本的JUnit没有org.junit.Assert 。 您可以使用最新版本的JUnit,但请注意,最近在JUnit中进行了一些不向后兼容的更改,因此您可能想询问测试作者使用的版本。 编辑:此外,您的pom.xml列出了具有范围“test”的JUnit(即仅作为您的测试的依赖项),这对大多数项目来说是正确的,但您的项目希望在生产代码中使用JUnit,所以将其更改为非测试依赖项。 正如Nizet所说,示例测试不是有效的测试。 Your pom lists JUnit ...