TypeScript typings for Google Drive API v2
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-v2 --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/v2/rest',
() => {
}
);
gapi.client.load('drive', 'v2', () => {
});
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.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.apps.get({ appId: "appId", });
await gapi.client.drive.apps.list({ });
await gapi.client.drive.changes.get({ changeId: "changeId", });
await gapi.client.drive.changes.getStartPageToken({ });
await gapi.client.drive.changes.list({ });
await gapi.client.drive.changes.watch({ });
await gapi.client.drive.channels.stop({ });
await gapi.client.drive.children.delete({ childId: "childId", folderId: "folderId", });
await gapi.client.drive.children.get({ childId: "childId", folderId: "folderId", });
await gapi.client.drive.children.insert({ folderId: "folderId", });
await gapi.client.drive.children.list({ folderId: "folderId", });
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.insert({ fileId: "fileId", });
await gapi.client.drive.comments.list({ fileId: "fileId", });
await gapi.client.drive.comments.patch({ commentId: "commentId", fileId: "fileId", });
await gapi.client.drive.comments.update({ commentId: "commentId", fileId: "fileId", });
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.insert({ requestId: "requestId", });
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", });
await gapi.client.drive.files.delete({ fileId: "fileId", });
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", });
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.insert` must specify the MIME type `application/vnd.google-apps.shortcut`. Apps should specify a file extension in the `title` property when inserting files with the API. For example, an operation to insert a JPEG file should specify something like `"title": "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.insert({ });
/*
Lists the user's files. This method accepts the `q` parameter, which is a search query combining one or more search terms. For more information, see the [Search for files & folders](/drive/api/guides/search-files) guide. *Note:* This method returns *all* files by default, including trashed files. If you don't want trashed files to appear in the list, use the `trashed=false` query parameter to remove trashed files from the results.
*/
await gapi.client.drive.files.list({ });
/*
Lists the labels on a file.
*/
await gapi.client.drive.files.listLabels({ fileId: "fileId", });
/*
Modifies the set of labels applied to a file. Returns a list of the labels that were added or modified.
*/
await gapi.client.drive.files.modifyLabels({ fileId: "fileId", });
/*
Updates a file's metadata and/or content. When calling this method, only populate fields in the request that you want to modify. When updating fields, some fields might change automatically, such as modifiedDate. This method supports patch semantics.
*/
await gapi.client.drive.files.patch({ fileId: "fileId", });
await gapi.client.drive.files.touch({ fileId: "fileId", });
await gapi.client.drive.files.trash({ fileId: "fileId", });
await gapi.client.drive.files.untrash({ 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.parents.delete({ fileId: "fileId", parentId: "parentId", });
await gapi.client.drive.parents.get({ fileId: "fileId", parentId: "parentId", });
await gapi.client.drive.parents.insert({ fileId: "fileId", });
await gapi.client.drive.parents.list({ 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.getIdForEmail({ email: "email", });
await gapi.client.drive.permissions.insert({ fileId: "fileId", });
await gapi.client.drive.permissions.list({ fileId: "fileId", });
await gapi.client.drive.permissions.patch({ fileId: "fileId", permissionId: "permissionId", });
await gapi.client.drive.permissions.update({ fileId: "fileId", permissionId: "permissionId", });
await gapi.client.drive.properties.delete({ fileId: "fileId", propertyKey: "propertyKey", });
await gapi.client.drive.properties.get({ fileId: "fileId", propertyKey: "propertyKey", });
await gapi.client.drive.properties.insert({ fileId: "fileId", });
await gapi.client.drive.properties.list({ fileId: "fileId", });
await gapi.client.drive.properties.patch({ fileId: "fileId", propertyKey: "propertyKey", });
await gapi.client.drive.properties.update({ fileId: "fileId", propertyKey: "propertyKey", });
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.insert({ commentId: "commentId", fileId: "fileId", });
await gapi.client.drive.replies.list({ commentId: "commentId", fileId: "fileId", });
await gapi.client.drive.replies.patch({ commentId: "commentId", fileId: "fileId", replyId: "replyId", });
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.patch({ fileId: "fileId", revisionId: "revisionId", });
await gapi.client.drive.revisions.update({ fileId: "fileId", revisionId: "revisionId", });
await gapi.client.drive.teamdrives.delete({ teamDriveId: "teamDriveId", });
await gapi.client.drive.teamdrives.get({ teamDriveId: "teamDriveId", });
await gapi.client.drive.teamdrives.insert({ requestId: "requestId", });
await gapi.client.drive.teamdrives.list({ });
await gapi.client.drive.teamdrives.update({ teamDriveId: "teamDriveId", });