forked from Like-Falling-Leaves/gmailer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetInfo.js
More file actions
27 lines (24 loc) · 692 Bytes
/
getInfo.js
File metadata and controls
27 lines (24 loc) · 692 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
var request = require('request');
var getFreshToken = require('./getFreshToken');
module.exports = getInfo;
function getInfo(accessToken, done) {
request({
url: 'https://www.googleapis.com/plus/v1/people/me',
headers: {
Authorization: 'Bearer ' + accessToken
}
}, function (err, response, body) {
if (err) return done(err);
try {
var info = JSON.parse(body);
var email = '';
if (info && info.emails && info.emails[0] && info.emails[0].value) {
email = info.emails[0].value;
}
var name = info.displayName || email;
return done(null, {email: email, name: name});
} catch (e) {
return done(e);
}
});
}