Skip to content

Instantly share code, notes, and snippets.

@Salamit
Last active May 14, 2019 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Salamit/4fd3a669bda18f50f0c31691a86ffe45 to your computer and use it in GitHub Desktop.
Save Salamit/4fd3a669bda18f50f0c31691a86ffe45 to your computer and use it in GitHub Desktop.
import '../modules/index.js';
import { Meteor } from 'meteor/meteor';
const {google} = require('googleapis');
const fs = require('fs');
Meteor.startup( function (){
Meteor.methods({
//credits: https://morioh.com/p/1313d7785668/node-js-using-google-sheets-api-with-oauth-2
//credits: http://www.gethugames.in/2012/04/authentication-and-authorization-for-google-apis-in-javascript-popup-window-tutorial.html
//authenticate the app to get access to user's google drive sheets
'googleAuth'(){
const path = process.env.PWD + '/credentials.json';
const credentials = JSON.parse(fs.readFileSync(path, 'utf-8'));
const {
client_secret: clientSecret,
client_id: clientId,
redirect_uris: redirectUris,
} = credentials.web;
const oauth2Client = new google.auth.OAuth2(
clientId, clientSecret, redirectUris[0],
);
// generate a url that asks permissions for Blogger and Google Calendar scopes
const scopes = [
'https://www.googleapis.com/auth/spreadsheets'
];
const url = oauth2Client.generateAuthUrl({
// 'online' (default) or 'offline' (gets refresh_token)
access_type: 'offline',
// If you only need one scope you can pass it as a string
scope: scopes
});
try {
return url
} catch(exception){
}
return url;
}
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment