Package Exports
- @buttercup/googledrive-client
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@buttercup/googledrive-client) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Google Drive Client
Client for making basic Google Drive requests
About
This library allows for performing basic actions against Google's RESTful Drive API. It supports fetching directory contents, reading files and writing files. Note that file reading & writing is only supported with text files currently. It uses axios to perform requests, which has been proven to be a stable cross-platform library perfect for this purpose.
Usage
Install the client by running the following:
npm install @buttercup/googledrive-clientThe library exports a factory which can be used to create client adapters. The factory takes a Google Drive OAuth token.
const { createClient } = require("@buttercup/googledrive-client");
const client = createClient(myToken);
client.getDirectoryContents({ tree: true }).then(tree => {
// ...
})
// Or return a flat structure with all files and directories:
client.getDirectoryContents();Make sure to check out the API documentation for more information.
Token Expiration or Invalid Credentials
This library uses VError to pass extra error information around, such as when authentication fails while making a request. This makes it easier for downstream libraries to handle such authorisation failures, perhaps by requesting a new token.
If an error is thrown, use VError to extract the information from it to test if an authorisation failure has occurred:
client.getDirectoryContents().catch(err => {
const { authFailure = false } = VError.info(err);
// handle authFailure === true
});