Hi
I was able to request for the token.
About the function you mentioned.I have few question as i was unable to
retrieve contacts.
I cound't understand the following.
req.user.identities[0].provider??
I appreciate your help.
function getContactsFromGoogleApi (req, res, next) {
if(req.user.identities[0].provider !== 'google-oauth2') return next();
request.get({
url: 'https://www.google.com/m8/feeds/contacts/default/full',
qs: {
alt: 'json',
'max-results': 1000,
'orderby': 'lastmodified'
},
headers: {
'Authorization': 'OAuth ' + req.user.identities[0].access_token,
'GData-Version': '3.0'
}
}, function (err, resp, body) {
if(resp.statusCode === 401){
return res.redirect('/login');
}
var feed = JSON.parse(body);
var users = feed.feed.entry.map(function (c) {
var r = {};
if(c['gd$name'] && ['gd$fullName']){
r.name = c['gd$name']['gd$fullName']['$t'];
}
if (c['gd$email'] && c['gd$email'].length > 0) {
r.email = c['gd$email'][0]['address'];
r.nickname = r.email;//c['gd$email'][0]['address'].split('@')[0];
}
if(c['link']){
var photoLink = c['link'].filter(function (link) {
return link.rel ==
'http://schemas.google.com/contacts/2008/rel#photo' &&
'gd$etag' in link;
})[0];
if(photoLink) {
r.picture = '/users/photo?l=' +
encodeURIComponent(photoLink.href);
} else if (r.email) {
r.picture = gravatar.url(r.email, {
s: 40,
d:
"https://ssl.gstatic.com/s2/profiles/images/silhouette80.png"});
}
}
return r;
}).filter(function (u) {
return !!u.email && //we can only give access to
persons with email at this point
!~u.email.indexOf('@reply.'); //adress with @reply. are
usually temporary reply address for forum kind of websites.
});
res.json(users);
});
}
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.