
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
google-api-fetch
Advanced tools
A lightweight implementation of Google API client using fetch for edge environments like Cloudflare Workers, Deno, and browsers.
npm install google-api-fetch
``` bash
## Usage
Basic setup
```javascript
import GoogleApi from 'google-api-fetch';
// Service account credentials
const credentials = {
client_email: 'your-service-account@project-id.iam.gserviceaccount.com',
private_key: '-----BEGIN PRIVATE KEY-----\n...your key...\n-----END PRIVATE KEY-----\n'
};
// Create a Google API client instance
const googleApi = new GoogleApi(credentials, {
enableRateLimiting: true,
maxConcurrentRequests: 5,
requestIntervalMs: 100
});
Drive API
// Initialize Drive API
const drive = googleApi.drive();
// List files
const filesList = await drive.files.list({
pageSize: 10,
fields: 'files(id, name, mimeType)'
});
// Get a file
const file = await drive.files.get({
fileId: 'your-file-id'
});
// Create a file
const newFile = await drive.files.create({
requestBody: {
name: 'My Document',
mimeType: 'application/vnd.google-apps.document'
},
media: {
mimeType: 'text/plain',
body: 'Hello, World!'
}
});
// Export a file to a different format
const exportedFile = await drive.files.export({
fileId: 'google-doc-id',
mimeType: 'application/pdf'
});
Sheets API
// Initialize Sheets API
const sheets = googleApi.sheets();
// Get a spreadsheet
const spreadsheet = await sheets.spreadsheets.get({
spreadsheetId: 'your-spreadsheet-id'
});
// Get values from a range
const values = await sheets.spreadsheets.values.get({
spreadsheetId: 'your-spreadsheet-id',
range: 'Sheet1!A1:D10'
});
// Update values in a range
const updateResult = await sheets.spreadsheets.values.update({
spreadsheetId: 'your-spreadsheet-id',
range: 'Sheet1!A1:D1',
valueInputOption: 'RAW',
resource: {
values: [['Value1', 'Value2', 'Value3', 'Value4']]
}
});
Docs API
// Initialize Docs API
const docs = googleApi.docs();
// Get a document
const document = await docs.documents.get({
documentId: 'your-document-id'
});
// Create a document
const newDocument = await docs.documents.create({
requestBody: {
title: 'New Document'
}
});
// Update a document
const updateResult = await docs.documents.batchUpdate({
documentId: 'your-document-id',
requestBody: {
requests: [
{
insertText: {
location: {
index: 1
},
text: 'Hello World!'
}
}
]
}
});
FAQs
A lightweight Google API client using fetch for edge environments
We found that google-api-fetch demonstrated a healthy version release cadence and project activity because the last version was released less than 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 Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.