Guest User

Google API Node js

a guest
Sep 15th, 2014
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //from ./lib/google.js
  2. var googleapis = require('googleapis');
  3. var OAuth2 = googleapis.auth.OAuth2;
  4. var client = new OAuth2('clientId', 'clientSecret', '/oauth2callback');
  5. var plus = googleapis.plus('v1');
  6. exports.client = client;
  7. exports.plus = plus;
  8.  
  9. //from app.js
  10. var gapi = require('./lib/google');
  11. app.get('/oauth2callback', function (req, res){
  12.     var code = req.query.code;
  13.     gapi.client.getToken(code, function (err, tokens) {
  14.         gapi.client.setCredentials(tokens);
  15.         gapi.plus.people.get({userId: 'me', auth: gapi.client}, function (err, resp){
  16.             //use the resp object to get user data we want...
  17.         });
  18.     });
  19. });
Add Comment
Please, Sign In to add comment