首页 \ 问答 \ 使用Google Drive API(PHP)列出文件时出错(Error listing files with Google Drive API (PHP))

使用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
更新时间:2021-11-03 14:11

最满意答案

看起来Artifactory在jcenter-cache中缓存了一个错过的检索。 如果Artifactory由于某种原因(例如超时)未能从JCenter获取junit,它将在远程存储库的“Missed Retrieval Cache Period”属性中配置的时间段内缓存此故障。
您可以清除此项并强制Artifactory尝试通过切换缓存来再次检索工件。

适用于这种情况:

  1. 转到工件>工件资源库浏览器> jcenter-cache> junit / junit> 4.12

    或者只需点击

    HTTP://我-自己的服务器:8081 / artifactory的/ web应用/#/神器/浏览/树/一般/ jcenter缓存/ JUnit的/ JUnit的/ 4.12

  2. 右键单击4.12> Zap Cache:

    右键单击和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:

  1. Go to Artifacts > Artifact Repository Browser > jcenter-cache > junit/junit > 4.12

    or just click on

    http://my-own-server:8081/artifactory/webapp/#/artifacts/browse/tree/General/jcenter-cache/junit/junit/4.12

  2. Right click on 4.12 > Zap Cache:

    right click and Zap Cache

相关问答

更多
  • @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 ...
  • 从版本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 -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 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)