
Product
Introducing Scala and Kotlin Support in Socket
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
google-api-wrapper
Advanced tools
Simple Wrapper around Google Sheets & Drive APIs
npm install google-api-wrapper
This will add googleapis as dependency.
const Google = require('google-api-wrapper');
async function main() {
Google.setCred(cred);
Google.setToken(token);
const sheet = Google.getSheet();
const rows = await sheet.read('1nZqgw5otHxvg7by-qnYmjkyNdHAPQYgduv7Tbf5aKlw');
console.log(rows);
}
main();
Google.loadCredFile(credentails.json);
Google.loadTokenFile(token.json);
Or,
Google.setCred(cred);
Google.setToken(token);
await sheet.read(id, range = 'Sheet1');
Returns two-dimensional array of rows and column values of sheet data.
sheet.set(id, range = 'Sheet1');
await sheet.clear();
await sheet.write(row1);
await sheet.write(row2);
await sheet.endWrite();
Batches up multiple rows and then write once at interval of 500 rows, or when endWrite() is called.
await sheet.create(name);
await sheet.write([ 'hello', 'there' ]);
await sheet.create(name, folderId);
const drive = Google.getDrive();
const file = drive.byId(fileId);
It returns a file object with { id, name, mimeType }
attributes.
drive.byName(name, type = null, folderId = null);
Example:
const drive = Google.getDrive();
let file;
file = drive.byName('My Document');
file = drive.byName('example.csv', 'type/csv', parentFolderId);
file = drive.byName('Example', null, parentFolderId);
It returns a file object with { id, name, mimeType }
attributes.
drive.list(folderId);
Example: to list all files under a folder named "My Folder"
const drive = Google.getDrive();
const folder = drive.byName('My Folder');
const files = drive.list(folder.id);
It returns an array of file objects with { id, name, mimeType }
attributes.
const drive = Google.getDrive();
await drive.readFile(id);
Returns string of file content.
const drive = Google.getDrive();
await drive.move(fileId, folderId);
drive object holds reference to Google API's drive object as a property. So to call the methods of Google Drive API.
For example, to list comments on a document named 'My Document', follow below
const Google = require('google-api-wrapper');
const drive = Google.getDrive();
const file = drive.byName('My Document');
// Below is call to underlying Google Drive API's method directly
const comments = drive.drive.comments.list({ fileId: file.id });
Similarly, Google Sheet object is stored as sheet property of wrapper's sheet object. methods on sheet.sheet can be made as per Google Sheet API.
const Google = require('google-api-wrapper');
const sheet = Google.getSheet();
// Calls underlying Google Sheet API
sheet.sheet.spreadsheets.batchGet(options);
To test the package,
# .env file
CRED_PATH=/path/to/credentials.json
TOKEN_PATH=/path/to/token.json
npm test
FAQs
Google API Wrapper
The npm package google-api-wrapper receives a total of 30 weekly downloads. As such, google-api-wrapper popularity was classified as not popular.
We found that google-api-wrapper demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
Application Security
/Security News
Socket CEO Feross Aboukhadijeh and a16z partner Joel de la Garza discuss vibe coding, AI-driven software development, and how the rise of LLMs, despite their risks, still points toward a more secure and innovative future.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.