Laravel 选择特定字段Google Drive API v3
我终于让GoogleDriveAPIv3与一个服务帐户一起工作 现在,要从驱动器检索所有文件,我使用以下命令:Laravel 选择特定字段Google Drive API v3,laravel,google-api,google-drive-api,google-api-php-client,Laravel,Google Api,Google Drive Api,Google Api Php Client,我终于让GoogleDriveAPIv3与一个服务帐户一起工作 现在,要从驱动器检索所有文件,我使用以下命令: $optParams = [ 'corpora' => 'drive', 'driveId' => env('GOOGLE_DRIVE_ID'), 'includeItemsFromAllDrives' => true, 'supportsAllDrives' => true, 'fields' => 'files(
$optParams = [
'corpora' => 'drive',
'driveId' => env('GOOGLE_DRIVE_ID'),
'includeItemsFromAllDrives' => true,
'supportsAllDrives' => true,
'fields' => 'files(name,mimeType,trashed,parents,version,webContentLink,webViewLink,createdTime,modifiedTime,size)'
];
$this->googleDrive->files->listFiles($optParams);
所以我特别要求文件数组中的某些字段。问题是,所有其他字段仍然存在(除了它们都是null值)。这是正常的行为吗?因为如果我试图检索20到50个文件,仍然有一些无用的Kb正在被传输
响应示例:
+"files": array:2 [▼
0 => Google_Service_Drive_DriveFile {#279 ▼
#collection_key: "spaces"
+appProperties: null
#capabilitiesType: "Google_Service_Drive_DriveFileCapabilities"
#capabilitiesDataType: ""
#contentHintsType: "Google_Service_Drive_DriveFileContentHints"
#contentHintsDataType: ""
+copyRequiresWriterPermission: null
+createdTime: "2019-05-22T11:41:25.852Z"
+description: null
+driveId: null
+explicitlyTrashed: null
+exportLinks: null
+fileExtension: null
+folderColorRgb: null
+fullFileExtension: null
+hasAugmentedPermissions: null
+hasThumbnail: null
+headRevisionId: null
+iconLink: null
+id: null
#imageMediaMetadataType: "Google_Service_Drive_DriveFileImageMediaMetadata"
#imageMediaMetadataDataType: ""
+isAppAuthorized: null
+kind: null
#lastModifyingUserType: "Google_Service_Drive_User"
#lastModifyingUserDataType: ""
+md5Checksum: null
+mimeType: "application/zip"
+modifiedByMe: null
+modifiedByMeTime: null
+modifiedTime: "2019-05-22T11:41:25.852Z"
+name: "<something>"
+originalFilename: null
+ownedByMe: null
#ownersType: "Google_Service_Drive_User"
#ownersDataType: "array"
+parents: array:1 [▶]
+permissionIds: null
#permissionsType: "Google_Service_Drive_Permission"
#permissionsDataType: "array"
+properties: null
+quotaBytesUsed: null
+shared: null
+sharedWithMeTime: null
#sharingUserType: "Google_Service_Drive_User"
#sharingUserDataType: ""
+size: "455778"
+spaces: null
+starred: null
+teamDriveId: null
+thumbnailLink: null
+thumbnailVersion: null
+trashed: false
+trashedTime: null
#trashingUserType: "Google_Service_Drive_User"
#trashingUserDataType: ""
+version: "2"
#videoMediaMetadataType: "Google_Service_Drive_DriveFileVideoMediaMetadata"
#videoMediaMetadataDataType: ""
+viewedByMe: null
+viewedByMeTime: null
+viewersCanCopyContent: null
+webContentLink: "<something>"
+webViewLink: "<something>"
+writersCanShare: null
#internal_gapi_mappings: []
#modelData: []
#processed: []
}
1 => Google_Service_Drive_DriveFile {#269 ▶}
+“文件”:数组:2[▼
0=>Google_服务_驱动器_驱动器文件{279▼
#集合\u键:“空格”
+appProperties:null
#能力类型:“谷歌\服务\硬盘\硬盘文件能力”
#capabilitiesDataType:“
#contentHintsType:“Google\u服务\u驱动器\u驱动器文件内容提示”
#contentHintsDataType:“
+copyRequiresWriterPermission:空
+创建时间:“2019-05-22T11:41:25.852Z”
+描述:空
+driveId:null
+explicitlyTrashed:null
+导出链接:null
+文件扩展名:null
+folderColorRgb:null
+fullFileExtension:null
+hasAugmentedPermissions:null
+hasThumbnail:空
+headlevisionid:null
+iconLink:null
+id:null
#imageMediaMetadataType:“Google\u服务\u驱动器\u驱动器文件ImageMediaMetadata”
#ImageMediaMetadataType:“
+isAppAuthorized:空
+种类:空
#lastModifyingUserType:“谷歌\服务\驱动器\用户”
#lastModifyingUserDataType:“
+md5Checksum:null
+mimeType:“应用程序/zip”
+modifiedByMe:null
+modifiedByMeTime:null
+修改时间:“2019-05-22T11:41:25.852Z”
+姓名:“
+原始文件名:null
+ownedByMe:空
#ownersType:“Google\u服务\u驱动器\u用户”
#ownersDataType:“数组”
+父:数组:1[▶]
+permissionId:null
#许可证类型:“谷歌服务驾驶许可证”
#permissionsDataType:“数组”
+属性:null
+quotaBytesUsed:null
+共享:空
+sharedWithMeTime:null
#sharingUserType:“谷歌服务驱动用户”
#sharingUserDataType:“
+尺寸:“455778”
+空格:空
+星号:空
+teamDriveId:null
+缩略图链接:空
+thumbnailVersion:空
+垃圾:假的
+trashedTime:null
#trashingUserType:“谷歌服务驱动用户”
#trashingUserDataType:“
+版本:“2”
#videoMediaMetadataType:“Google\u服务\u驱动器\u驱动器文件VideoMediaMetadata”
#VideoMediaMetadataType:“
+viewedByMe:null
+viewedByMeTime:null
+viewersCanCopyContent:空
+WebContent链接:“
+webViewLink:“
+writersCanShare:空
#内部_-gapi_映射:[]
#模型数据:[]
#已处理:[]
}
1=>Google_服务_驱动器_驱动器文件{#269▶}
google drive api v3实现了一个称为的东西,实际上大多数google api都有这个选项,这是一个可选的parm
默认情况下,服务器在处理请求后发回资源的完整表示形式。为了获得更好的性能,您可以要求服务器仅发送您真正需要的字段,并获得部分响应
由于上述陈述是正确的,因此其IMO并非每一个都有很好的记录
Drive v3默认情况下不返回完整的表示。这是Drive v3和其他API的主要区别,通常默认情况下是返回所有内容,并且只有在开发人员使用parm字段请求时才执行部分响应
drive files.list响应包含一个文件列表,默认情况下,它只会向您返回以下4个字段
{
"kind": "drive#file",
"id": "hzqXfMiOiFlrYdQCx3Rram0vuf9lmXa",
"name": "Sayak",
"mimeType": "application/vnd.google-apps.folder"
}
您看到的空值实际上可能来自您正在使用的库,该库将空对象值解析为空值
如果你做了一个
$optParams = [
'corpora' => 'drive',
'driveId' => env('GOOGLE_DRIVE_ID'),
'includeItemsFromAllDrives' => true,
'supportsAllDrives' => true,
'fields' => '*'
];
事实上,它将为您填写所有字段。我使用的是API…Google官方API不应该考虑字段选项吗?客户端库是自动生成的。PHP中解析对象的方式意味着,如果类包含字段但未填写,则它将显示为空。