Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

google-authorize

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

google-authorize

Get an OAuth2 client with authorized token to be used with Google APIs.

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
18
increased by63.64%
Maintainers
1
Weekly downloads
 
Created
Source

Google Authorize

Get an OAuth2 client with an authorized token to be used with Google APIs.

All I want for Christmas is to be able to easily start working with the Google APIs. There is a nice Node quickstart that Google provides for this. This module is a wrapper of that code but instead of executing a callback function that passes a resultant OAuth2 client, it returns a Promise that is thenable which resolves the OAuth2 client.

Here's how to use it:

Visit Node quickstart and complete Step 1 to get your client_secret.json.

npm i google-authorize --save
const GoogleAuthorize = require('google-authorize');

// Use an array of scopes that correlate to to googleapi scopes
// i.e. ['spreadsheets'] -> https://www.googleapis.com/auth/spreadsheets
const googleAuth = new GoogleAuthorize(['spreadsheets']);

// Authorize and then make a request to the sheets API
googleAuth.authorize().then(listMajors);

function listMajors(auth) {
  var sheets = require('googleapis').sheets('v4');
  sheets.spreadsheets.values.get({
    auth: auth,
    spreadsheetId: '1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms',
    range: 'Class Data!A2:E',
  }, function(err, response) {
    if (err) {
      console.log('The API returned an error: ' + err);
      return;
    }
    var rows = response.values;
    if (rows.length == 0) {
      console.log('No data found.');
    } else {
      console.log('Name, Major:');
      for (var i = 0; i < rows.length; i++) {
        var row = rows[i];
        // Print columns A and E, which correspond to indices 0 and 4.
        console.log('%s, %s', row[0], row[4]);
      }
    }
  });
}

## Change Log
Nov 6 2018 - Fixed undefined callback on fs.writeFile

Keywords

FAQs

Package last updated on 06 Nov 2018

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc