答案 0 :(得分:0)
这样可行(假设您的凭据有序且您已获得授权):
function getFileInfo(fileId, callback) { try { gapi.client.drive.files.get({ fileId: fileId, fields: "appProperties,capabilities,contentHints,createdTime,description,explicitlyTrashed,fileExtension,folderColorRgb,fullFileExtension,headRevisionId,iconLink,id,imageMediaMetadata,isAppAuthorized,kind,lastModifyingUser,md5Checksum,mimeType,modifiedByMeTime,modifiedTime,name,originalFilename,ownedByMe,owners,parents,permissions,properties,quotaBytesUsed,shared,sharedWithMeTime,sharingUser,size,spaces,starred,thumbnailLink,trashed,version,videoMediaMetadata,viewedByMe,viewedByMeTime,viewersCanCopyContent,webContentLink,webViewLink,writersCanShare", }).then(function(response) { info = JSON.parse(response.body); callback(info); }) } catch (err) { console.log('Something bad happened: ' + err); } }
它返回所有已知的元数据字段(截至此时)。您希望将列表修剪为您需要的列表。但它不会返回实际的电子表格内容。为此,您需要使用export api:
function getSpreadsheet(fileId, callback) { var spreadsheet; try { gapi.client.drive.files.export({ fileId: fileId, mimeType: 'text/csv' }).then(function(response) { spreadsheet = Papa.parse(response.body).data; callback(spreadsheet); }) } catch (err) { console.log('Something bad happened: ' + err); } }
数据以csv字符串形式返回。我们使用Papa.parse将其转换为2D数组。