0

我使用库项目:google-api-php-client-0.6.1.tar.gts。复制示例https://developers.google.com/drive/v2/reference/about/get?hl=ru

function printAbout($service) {
  try {
   $about = $service->about->get();

   print "Current user name: " . $about->getName();
   print "Root folder ID: " . $about->getRootFolderId();
   print "Total quota (bytes): " . $about->getQuotaBytesTotal();
   print "Used quota (bytes): " . $about->getQuotaBytesUsed();
  } catch (Exception $e) {
   print "An error occurred: " . $e->getMessage();
  }
}

PHP错误:致命错误:调用非对象中的成员函数getName()......
$about未分配给对象,并且数组类型:

Array (
[kind] => drive#file
[id] => 0B6xE_F1PfpXTWUVUNE5nZW5qYUU
[etag] => "Ys3khhcpAWaV7oeqaRGUOvsvqpo/MTM2MjEyNTY4MjE5NA"
[selfLink] => https://www.googleapis.com/drive/v2/files/0B6xE_F1PfpXTWUVUNE5nZW5qYUU
[webContentLink] => https://docs.google.com/uc?id=0B6xE_F1PfpXTWUVUNE5nZW5qYUU&export=download
[alternateLink] => https://docs.google.com/file/d/0B6xE_F1PfpXTWUVUNE5nZW5qYUU/edit
[iconLink] => https://ssl.gstatic.com/docs/doclist/images/icon_10_word_list.png
[thumbnailLink] => https://lh5.googleusercontent.com/Mb3p9nFVuzwGaaKVVxfyBKwPOS4-0QjiSUi7EcfiA6_QBgRThM7NrPOcBC-UcRKt6Q=s220
[title] => Kniga3_A5.doc
[mimeType] => application/msword
[labels] => Array
    (
        [starred] => 
        [hidden] => 
        [trashed] => 
        [restricted] => 
        [viewed] => 
    )

[createdDate] => 2013-03-01T08:14:40.352Z
[modifiedDate] => 2013-03-01T08:14:42.194Z
[modifiedByMeDate] => 2013-03-01T08:14:40.332Z
[parents] => Array ..................

在函数 printFile 中获得了数组的一个示例,但它的格式与 printAbout 中的相同。
我认为应该给予对象......
我在其他功能中注意到的同样错误。

4

1 回答 1

0

PHP 客户端库可以返回关联数组或对象,示例假定您正在获取对象。要配置此行为,您可以use_objects在以下位置设置属性$apiConfig

https://code.google.com/p/google-api-php-client/source/browse/trunk/src/config.php#22

于 2013-03-01T18:56:58.877 回答