TypeScript typings for Google Drive API v3
The Google Drive API allows clients to access resources from Google Drive.
For detailed description please check documentation.
Installing
Install typings for Google Drive API:
npm install @types/gapi.client.drive-v3 --save-dev
Usage
You need to initialize Google API client in your code:
gapi.load('client', () => {
});
Then load api client wrapper:
gapi.client.load(
'https://www.googleapis.com/discovery/v1/apis/drive/v3/rest',
() => {
}
);
gapi.client.load('drive', 'v3', () => {
});
Don't forget to authenticate your client before sending any request to resources:
var client_id = '',
scope = [
'https://www.googleapis.com/auth/drive',
'https://www.googleapis.com/auth/drive.appdata',
'https://www.googleapis.com/auth/drive.apps.readonly',
'https://www.googleapis.com/auth/drive.file',
'https://www.googleapis.com/auth/drive.meet.readonly',
'https://www.googleapis.com/auth/drive.metadata',
'https://www.googleapis.com/auth/drive.metadata.readonly',
'https://www.googleapis.com/auth/drive.photos.readonly',
'https://www.googleapis.com/auth/drive.readonly',
'https://www.googleapis.com/auth/drive.scripts',
],
immediate = true;
gapi.auth.authorize(
{client_id: client_id, scope: scope, immediate: immediate},
authResult => {
if (authResult && !authResult.error) {
} else {
}
}
);
After that you can use Google Drive API resources:
await gapi.client.drive.about.get({ });
await gapi.client.drive.accessproposals.get({ fileId: "fileId", proposalId: "proposalId", });
await gapi.client.drive.accessproposals.list({ fileId: "fileId", });
await gapi.client.drive.accessproposals.resolve({ fileId: "fileId", proposalId: "proposalId", });
await gapi.client.drive.apps.get({ appId: "appId", });
await gapi.client.drive.apps.list({ });
await gapi.client.drive.changes.getStartPageToken({ });
await gapi.client.drive.changes.list({ pageToken: "pageToken", });
await gapi.client.drive.changes.watch({ pageToken: "pageToken", });
await gapi.client.drive.channels.stop({ });
await gapi.client.drive.comments.create({ fileId: "fileId", });
await gapi.client.drive.comments.delete({ commentId: "commentId", fileId: "fileId", });
await gapi.client.drive.comments.get({ commentId: "commentId", fileId: "fileId", });
await gapi.client.drive.comments.list({ fileId: "fileId", });
await gapi.client.drive.comments.update({ commentId: "commentId", fileId: "fileId", });
await gapi.client.drive.drives.create({ requestId: "requestId", });
await gapi.client.drive.drives.delete({ driveId: "driveId", });
await gapi.client.drive.drives.get({ driveId: "driveId", });
await gapi.client.drive.drives.hide({ driveId: "driveId", });
await gapi.client.drive.drives.list({ });
await gapi.client.drive.drives.unhide({ driveId: "driveId", });
await gapi.client.drive.drives.update({ driveId: "driveId", });
await gapi.client.drive.files.copy({ fileId: "fileId", });
upload* URI and accepts uploaded media with the following characteristics: - *Maximum file size:* 5,120 GB - *Accepted Media MIME types:*`*/*` Note: Specify a valid MIME type, rather than the literal `*/*` value. The literal `*/*` is only used to indicate that any valid MIME type can be uploaded. For more information on uploading files, see [Upload file data](/drive/api/guides/manage-uploads). Apps creating shortcuts with `files.create` must specify the MIME type `application/vnd.google-apps.shortcut`. Apps should specify a file extension in the `name` property when inserting files with the API. For example, an operation to insert a JPEG file should specify something like `"name": "cat.jpg"` in the metadata. Subsequent `GET` requests include the read-only `fileExtension` property populated with the extension originally specified in the `title` property. When a Google Drive user requests to download a file, or when the file is downloaded through the sync client, Drive builds a full filename (with extension) based on the title. In cases where the extension is missing, Drive attempts to determine the extension based on the file's MIME type.
*/
await gapi.client.drive.files.create({ });
/*
Permanently deletes a file owned by the user without moving it to the trash. If the file belongs to a shared drive, the user must be an `organizer` on the parent folder. If the target is a folder, all descendants owned by the user are also deleted.
*/
await gapi.client.drive.files.delete({ fileId: "fileId", });
/*
Downloads content of a file. Operations are valid for 24 hours from the time of creation.
*/
await gapi.client.drive.files.download({ fileId: "fileId", });
/*
Permanently deletes all of the user's trashed files.
*/
await gapi.client.drive.files.emptyTrash({ });
await gapi.client.drive.files.export({ fileId: "fileId", mimeType: "mimeType", });
await gapi.client.drive.files.generateIds({ });
await gapi.client.drive.files.get({ fileId: "fileId", });
await gapi.client.drive.files.list({ });
await gapi.client.drive.files.listLabels({ fileId: "fileId", });
await gapi.client.drive.files.modifyLabels({ fileId: "fileId", });
upload* URI and accepts uploaded media with the following characteristics: - *Maximum file size:* 5,120 GB - *Accepted Media MIME types:*`*/*` Note: Specify a valid MIME type, rather than the literal `*/*` value. The literal `*/*` is only used to indicate that any valid MIME type can be uploaded. For more information on uploading files, see [Upload file data](/drive/api/guides/manage-uploads).
*/
await gapi.client.drive.files.update({ fileId: "fileId", });
await gapi.client.drive.files.watch({ fileId: "fileId", });
await gapi.client.drive.operation.cancel({ name: "name", });
await gapi.client.drive.operation.delete({ name: "name", });
await gapi.client.drive.operations.get({ name: "name", });
await gapi.client.drive.operations.list({ });
await gapi.client.drive.permissions.create({ fileId: "fileId", });
await gapi.client.drive.permissions.delete({ fileId: "fileId", permissionId: "permissionId", });
await gapi.client.drive.permissions.get({ fileId: "fileId", permissionId: "permissionId", });
await gapi.client.drive.permissions.list({ fileId: "fileId", });
await gapi.client.drive.permissions.update({ fileId: "fileId", permissionId: "permissionId", });
await gapi.client.drive.replies.create({ commentId: "commentId", fileId: "fileId", });
await gapi.client.drive.replies.delete({ commentId: "commentId", fileId: "fileId", replyId: "replyId", });
await gapi.client.drive.replies.get({ commentId: "commentId", fileId: "fileId", replyId: "replyId", });
await gapi.client.drive.replies.list({ commentId: "commentId", fileId: "fileId", });
await gapi.client.drive.replies.update({ commentId: "commentId", fileId: "fileId", replyId: "replyId", });
await gapi.client.drive.revisions.delete({ fileId: "fileId", revisionId: "revisionId", });
await gapi.client.drive.revisions.get({ fileId: "fileId", revisionId: "revisionId", });
await gapi.client.drive.revisions.list({ fileId: "fileId", });
await gapi.client.drive.revisions.update({ fileId: "fileId", revisionId: "revisionId", });
await gapi.client.drive.teamdrives.create({ requestId: "requestId", });
await gapi.client.drive.teamdrives.delete({ teamDriveId: "teamDriveId", });
await gapi.client.drive.teamdrives.get({ teamDriveId: "teamDriveId", });
await gapi.client.drive.teamdrives.list({ });
await gapi.client.drive.teamdrives.update({ teamDriveId: "teamDriveId", });