Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
@maxim_mazurok/gapi.client.drive-v2
Advanced tools
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.
Install typings for Google Drive API:
npm install @types/gapi.client.drive-v2 --save-dev
You need to initialize Google API client in your code:
gapi.load('client', () => {
// now we can use gapi.client
// ...
});
Then load api client wrapper:
gapi.client.load(
'https://www.googleapis.com/discovery/v1/apis/drive/v2/rest',
() => {
// now we can use:
// gapi.client.drive
}
);
// Deprecated, use discovery document URL, see https://github.com/google/google-api-javascript-client/blob/master/docs/reference.md#----gapiclientloadname----version----callback--
gapi.client.load('drive', 'v2', () => {
// now we can use:
// gapi.client.drive
});
Don't forget to authenticate your client before sending any request to resources:
// declare client_id registered in Google Developers Console
var client_id = '',
scope = [
// See, edit, create, and delete all of your Google Drive files
'https://www.googleapis.com/auth/drive',
// See, create, and delete its own configuration data in your Google Drive
'https://www.googleapis.com/auth/drive.appdata',
// View your Google Drive apps
'https://www.googleapis.com/auth/drive.apps.readonly',
// See, edit, create, and delete only the specific Google Drive files you use with this app
'https://www.googleapis.com/auth/drive.file',
// See and download your Google Drive files that were created or edited by Google Meet.
'https://www.googleapis.com/auth/drive.meet.readonly',
// View and manage metadata of files in your Google Drive
'https://www.googleapis.com/auth/drive.metadata',
// See information about your Google Drive files
'https://www.googleapis.com/auth/drive.metadata.readonly',
// View the photos, videos and albums in your Google Photos
'https://www.googleapis.com/auth/drive.photos.readonly',
// See and download all your Google Drive files
'https://www.googleapis.com/auth/drive.readonly',
// Modify your Google Apps Script scripts' behavior
'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) {
/* handle successful authorization */
} else {
/* handle authorization error */
}
}
);
After that you can use Google Drive API resources:
/*
Gets the information about the current user along with Drive API settings
*/
await gapi.client.drive.about.get({ });
/*
Gets a specific app.
*/
await gapi.client.drive.apps.get({ appId: "appId", });
/*
Lists a user's installed apps.
*/
await gapi.client.drive.apps.list({ });
/*
Deprecated: Use `changes.getStartPageToken` and `changes.list` to retrieve recent changes.
*/
await gapi.client.drive.changes.get({ changeId: "changeId", });
/*
Gets the starting pageToken for listing future changes.
*/
await gapi.client.drive.changes.getStartPageToken({ });
/*
Lists the changes for a user or shared drive.
*/
await gapi.client.drive.changes.list({ });
/*
Subscribe to changes for a user.
*/
await gapi.client.drive.changes.watch({ });
/*
Stops watching resources through this channel.
*/
await gapi.client.drive.channels.stop({ });
/*
Removes a child from a folder.
*/
await gapi.client.drive.children.delete({ childId: "childId", folderId: "folderId", });
/*
Gets a specific child reference.
*/
await gapi.client.drive.children.get({ childId: "childId", folderId: "folderId", });
/*
Inserts a file into a folder.
*/
await gapi.client.drive.children.insert({ folderId: "folderId", });
/*
Lists a folder's children.
*/
await gapi.client.drive.children.list({ folderId: "folderId", });
/*
Deletes a comment.
*/
await gapi.client.drive.comments.delete({ commentId: "commentId", fileId: "fileId", });
/*
Gets a comment by ID.
*/
await gapi.client.drive.comments.get({ commentId: "commentId", fileId: "fileId", });
/*
Creates a new comment on the given file.
*/
await gapi.client.drive.comments.insert({ fileId: "fileId", });
/*
Lists a file's comments.
*/
await gapi.client.drive.comments.list({ fileId: "fileId", });
/*
Updates an existing comment.
*/
await gapi.client.drive.comments.patch({ commentId: "commentId", fileId: "fileId", });
/*
Updates an existing comment.
*/
await gapi.client.drive.comments.update({ commentId: "commentId", fileId: "fileId", });
/*
Permanently deletes a shared drive for which the user is an `organizer`. The shared drive cannot contain any untrashed items.
*/
await gapi.client.drive.drives.delete({ driveId: "driveId", });
/*
Gets a shared drive's metadata by ID.
*/
await gapi.client.drive.drives.get({ driveId: "driveId", });
/*
Hides a shared drive from the default view.
*/
await gapi.client.drive.drives.hide({ driveId: "driveId", });
/*
Creates a new shared drive.
*/
await gapi.client.drive.drives.insert({ requestId: "requestId", });
/*
Lists the user's shared drives. This method accepts the `q` parameter, which is a search query combining one or more search terms. For more information, see the [Search for shared drives](/drive/api/guides/search-shareddrives) guide.
*/
await gapi.client.drive.drives.list({ });
/*
Restores a shared drive to the default view.
*/
await gapi.client.drive.drives.unhide({ driveId: "driveId", });
/*
Updates the metadata for a shared drive.
*/
await gapi.client.drive.drives.update({ driveId: "driveId", });
/*
Creates a copy of the specified file.
*/
await gapi.client.drive.files.copy({ fileId: "fileId", });
/*
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", });
/*
Permanently deletes all of the user's trashed files.
*/
await gapi.client.drive.files.emptyTrash({ });
/*
Exports a Google Workspace document to the requested MIME type and returns exported byte content. Note that the exported content is limited to 10MB.
*/
await gapi.client.drive.files.export({ fileId: "fileId", mimeType: "mimeType", });
/*
Generates a set of file IDs which can be provided in insert or copy requests.
*/
await gapi.client.drive.files.generateIds({ });
/*
Gets a file's metadata or content by ID. If you provide the URL parameter `alt=media`, then the response includes the file contents in the response body. Downloading content with `alt=media` only works if the file is stored in Drive. To download Google Docs, Sheets, and Slides use [`files.export`](/drive/api/reference/rest/v2/files/export) instead. For more information, see [Download & export files](/drive/api/guides/manage-downloads).
*/
await gapi.client.drive.files.get({ fileId: "fileId", });
/*
Inserts a new file. This method supports an */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", });
/*
Set the file's updated time to the current server time.
*/
await gapi.client.drive.files.touch({ fileId: "fileId", });
/*
Moves a file to the trash. The currently authenticated user must own the file or be at least a `fileOrganizer` on the parent for shared drive files.
*/
await gapi.client.drive.files.trash({ fileId: "fileId", });
/*
Restores a file from the trash. The currently authenticated user must own the file or be at least a `fileOrganizer` on the parent for shared drive files.
*/
await gapi.client.drive.files.untrash({ 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 be changed automatically, such as `modifiedDate`. This method supports patch semantics. This method supports an */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", });
/*
Subscribes to changes to a file.
*/
await gapi.client.drive.files.watch({ fileId: "fileId", });
/*
Removes a parent from a file.
*/
await gapi.client.drive.parents.delete({ fileId: "fileId", parentId: "parentId", });
/*
Gets a specific parent reference.
*/
await gapi.client.drive.parents.get({ fileId: "fileId", parentId: "parentId", });
/*
Adds a parent folder for a file.
*/
await gapi.client.drive.parents.insert({ fileId: "fileId", });
/*
Lists a file's parents.
*/
await gapi.client.drive.parents.list({ fileId: "fileId", });
/*
Deletes a permission from a file or shared drive. **Warning:** Concurrent permissions operations on the same file are not supported; only the last update is applied.
*/
await gapi.client.drive.permissions.delete({ fileId: "fileId", permissionId: "permissionId", });
/*
Gets a permission by ID.
*/
await gapi.client.drive.permissions.get({ fileId: "fileId", permissionId: "permissionId", });
/*
Returns the permission ID for an email address.
*/
await gapi.client.drive.permissions.getIdForEmail({ email: "email", });
/*
Inserts a permission for a file or shared drive. **Warning:** Concurrent permissions operations on the same file are not supported; only the last update is applied.
*/
await gapi.client.drive.permissions.insert({ fileId: "fileId", });
/*
Lists a file's or shared drive's permissions.
*/
await gapi.client.drive.permissions.list({ fileId: "fileId", });
/*
Updates a permission using patch semantics. **Warning:** Concurrent permissions operations on the same file are not supported; only the last update is applied.
*/
await gapi.client.drive.permissions.patch({ fileId: "fileId", permissionId: "permissionId", });
/*
Updates a permission. **Warning:** Concurrent permissions operations on the same file are not supported; only the last update is applied.
*/
await gapi.client.drive.permissions.update({ fileId: "fileId", permissionId: "permissionId", });
/*
Deletes a property.
*/
await gapi.client.drive.properties.delete({ fileId: "fileId", propertyKey: "propertyKey", });
/*
Gets a property by its key.
*/
await gapi.client.drive.properties.get({ fileId: "fileId", propertyKey: "propertyKey", });
/*
Adds a property to a file, or updates it if it already exists.
*/
await gapi.client.drive.properties.insert({ fileId: "fileId", });
/*
Lists a file's properties.
*/
await gapi.client.drive.properties.list({ fileId: "fileId", });
/*
Updates a property.
*/
await gapi.client.drive.properties.patch({ fileId: "fileId", propertyKey: "propertyKey", });
/*
Updates a property.
*/
await gapi.client.drive.properties.update({ fileId: "fileId", propertyKey: "propertyKey", });
/*
Deletes a reply.
*/
await gapi.client.drive.replies.delete({ commentId: "commentId", fileId: "fileId", replyId: "replyId", });
/*
Gets a reply.
*/
await gapi.client.drive.replies.get({ commentId: "commentId", fileId: "fileId", replyId: "replyId", });
/*
Creates a new reply to the given comment.
*/
await gapi.client.drive.replies.insert({ commentId: "commentId", fileId: "fileId", });
/*
Lists all of the replies to a comment.
*/
await gapi.client.drive.replies.list({ commentId: "commentId", fileId: "fileId", });
/*
Updates an existing reply.
*/
await gapi.client.drive.replies.patch({ commentId: "commentId", fileId: "fileId", replyId: "replyId", });
/*
Updates an existing reply.
*/
await gapi.client.drive.replies.update({ commentId: "commentId", fileId: "fileId", replyId: "replyId", });
/*
Permanently deletes a file version. You can only delete revisions for files with binary content, like images or videos. Revisions for other files, like Google Docs or Sheets, and the last remaining file version can't be deleted.
*/
await gapi.client.drive.revisions.delete({ fileId: "fileId", revisionId: "revisionId", });
/*
Gets a specific revision.
*/
await gapi.client.drive.revisions.get({ fileId: "fileId", revisionId: "revisionId", });
/*
Lists a file's revisions.
*/
await gapi.client.drive.revisions.list({ fileId: "fileId", });
/*
Updates a revision.
*/
await gapi.client.drive.revisions.patch({ fileId: "fileId", revisionId: "revisionId", });
/*
Updates a revision.
*/
await gapi.client.drive.revisions.update({ fileId: "fileId", revisionId: "revisionId", });
/*
Deprecated: Use `drives.delete` instead.
*/
await gapi.client.drive.teamdrives.delete({ teamDriveId: "teamDriveId", });
/*
Deprecated: Use `drives.get` instead.
*/
await gapi.client.drive.teamdrives.get({ teamDriveId: "teamDriveId", });
/*
Deprecated: Use `drives.insert` instead.
*/
await gapi.client.drive.teamdrives.insert({ requestId: "requestId", });
/*
Deprecated: Use `drives.list` instead.
*/
await gapi.client.drive.teamdrives.list({ });
/*
Deprecated: Use `drives.update` instead.
*/
await gapi.client.drive.teamdrives.update({ teamDriveId: "teamDriveId", });
FAQs
TypeScript typings for Google Drive API v2
We found that @maxim_mazurok/gapi.client.drive-v2 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.