dongpenggan6812 2016-12-12 17:16
浏览 70

谷歌驱动器api文件下载。 WebcontentLink为NULL

I am trying to download a file via google api. I came across that I need to retrive a webContentLink but unfortunetly this property is st

This is my code a part of my code:

$service = new Google_Service_Drive($client);

// Print the names and IDs for up to 10 files.
$optParams = array(
  'pageSize' => 1,
  'fields' => 'nextPageToken, files(id, name)'
);
$results = $service->files->listFiles($optParams);

$zdjecie = '/home/bachus03/domains/bachus03.vot.pl/public_html/fb/public/test.jpg';

if (count($results->getFiles()) == 0) {
  print "No files found.
";
} else {
  print "Files:
";
  foreach ($results->getFiles() as $file) {
    printf("%s (%s)
", $file->getName(), $file->getId());
    $file_full = $service->files->get($file->getId());
    /*printFile($service, $file_full);
    file_put_contents($zdjecie, $file_content);
    print "zapisano zdjecie"; */
    var_dump($file_full);
  }

and this is what I get in output:

[bachus03@s14:: ~ ]:$ /usr/local/php/p56/bin/php /home/bachus03/domains/bachus03.vot.pl/public_html/fb/public/quickstart.php

Files:
20161209_170813.JPG (1Nt9twwwwj-D2qKpmIga_T0pRCs2JxvyfvA)
object(Google_Service_Drive_DriveFile)#53 (56) {
  ["collection_key":protected]=>
  string(6) "spaces"
  ["appProperties"]=>
  NULL
  ["capabilitiesType":protected]=>
  string(42) "Google_Service_Drive_DriveFileCapabilities"
  ["capabilitiesDataType":protected]=>
  string(0) ""
  ["contentHintsType":protected]=>
  string(42) "Google_Service_Drive_DriveFileContentHints"
  ["contentHintsDataType":protected]=>
  string(0) ""
  ["createdTime"]=>
  NULL
  ["description"]=>
  NULL
  ["explicitlyTrashed"]=>
  NULL
  ["fileExtension"]=>
  NULL
  ["folderColorRgb"]=>
  NULL
  ["fullFileExtension"]=>
  NULL
  ["headRevisionId"]=>
  NULL
  ["iconLink"]=>
  NULL
  ["id"]=>
  string(35) "1Nt9twwwwj-D2qKpmIga_T0pRCs2JxvyfvA"
  ["imageMediaMetadataType":protected]=>
  string(48) "Google_Service_Drive_DriveFileImageMediaMetadata"
  ["imageMediaMetadataDataType":protected]=>
  string(0) ""
  ["isAppAuthorized"]=>
  NULL
  ["kind"]=>
  string(10) "drive#file"
  ["lastModifyingUserType":protected]=>
  string(25) "Google_Service_Drive_User"
  ["lastModifyingUserDataType":protected]=>
  string(0) ""
  ["md5Checksum"]=>
  NULL
  ["mimeType"]=>
  string(10) "image/jpeg"
  ["modifiedByMeTime"]=>
  NULL
  ["modifiedTime"]=>
  NULL
  ["name"]=>
  string(19) "20161209_170813.JPG"
  ["originalFilename"]=>
  NULL
  ["ownedByMe"]=>
  NULL
  ["ownersType":protected]=>
  string(25) "Google_Service_Drive_User"
  ["ownersDataType":protected]=>
  string(5) "array"
  ["parents"]=>
  NULL
  ["permissionsType":protected]=>
  string(31) "Google_Service_Drive_Permission"
  ["permissionsDataType":protected]=>
  string(5) "array"
  ["properties"]=>
  NULL
  ["quotaBytesUsed"]=>
  NULL
  ["shared"]=>
  NULL
  ["sharedWithMeTime"]=>
  NULL
  ["sharingUserType":protected]=>
  string(25) "Google_Service_Drive_User"
  ["sharingUserDataType":protected]=>
  string(0) ""
  ["size"]=>
  NULL
  ["spaces"]=>
  NULL
  ["starred"]=>
  NULL
  ["thumbnailLink"]=>
  NULL
  ["trashed"]=>
  NULL
  ["version"]=>
  NULL
  ["videoMediaMetadataType":protected]=>
  string(48) "Google_Service_Drive_DriveFileVideoMediaMetadata"
  ["videoMediaMetadataDataType":protected]=>
  string(0) ""
  ["viewedByMe"]=>
  NULL
  ["viewedByMeTime"]=>
  NULL
  ["viewersCanCopyContent"]=>
  NULL
  ["webContentLink"]=>
  NULL
  ["webViewLink"]=>
  NULL
  ["writersCanShare"]=>
  NULL
  ["internal_gapi_mappings":protected]=>
  array(0) {
  }
  ["modelData":protected]=>
  array(0) {
  }
  ["processed":protected]=>
  array(0) {
  }
}

What a i am doing wrong ?

  • 写回答

1条回答 默认 最新

  • dongzhan7253 2016-12-13 11:14
    关注

    The other main part is you will have to do a files.get request from the id returned in the files.insert call - you will not be able to do it in a single API call on just the insert.

    webContentLink can be accessed once the Files resource were retrieve (ie, using get). Based on the documentation. Insert should be able to have webContentLink as well since it also uses Files resources for its response

    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测