node.js - How to get Google contacts without access token? -
updated
i got answer still of access token
:)
and going mention it.
i using google contacts api
user
contacts.
i using passport.js login google , of passport's access token
calling api
https://www.google.com/m8/feeds/contacts/default/full?max-results=999999&alt=json&oauth_token=' + token
and getting contacts
but need use else instead of access token
secret key
or client key
.
because every time need log in
google
syncing contacts
if user added newly contact
.
i did google
didn't solution.
any idea helpful me.
here code contacts
var getgooglecontacts = function(token, userid) { var url = 'https://www.google.com/m8/feeds/contacts/default/full?max-results=999999&alt=json&oauth_token=' + token; request(url, function(error, response, body) { if (error) { console.log(error); } else { var contacts = json.parse(body); savegooglecontacts(userid, contacts); } }); }; /*get contacts , store in user_contact table*/ var savegooglecontacts = function(userid, contacts) { var gcontacts = []; contacts.feed.entry.foreach(function(contact, index) { if (contacts.feed.entry[index].gd$email) { gcontacts.push([ null, null, contacts.feed.entry[index].title.$t, "'" + contacts.feed.entry[index].gd$email[0].address + "'", 1, userid, 0 ]); } }); if (gcontacts.length > 0) { user.insertcontacts(gcontacts, function(err, result) { if (err) { console.log(err); } else { console.log('contacts saved: ' + result); } }); }else{ console.log('no records available'); } };
here got answer.
as mentioned using passport.js
log in google
and during log in process passport
provides access token
, refresh token
default refresh token
null
.
if want refresh token
need pass parameter
accesstype:offline
during authentication process, this
app.get('/auth/google', passport.authenticate('google', { scope : ['profile', 'email','https://www.google.com/m8/feeds'],accesstype: 'offline', approvalprompt: 'force' }));
after you'll refresh token
, store in permanent place since not expire
, can use whenever want access token
to access token
using refresh-token module.
after gertting token
need call api
contacts.
like this
var url = 'https://www.google.com/m8/feeds/contacts/default/full?max-results=999999&alt=json&oauth_token=' + token; request(url, function(error, response, body) { if (error) { cb(error); } else { var contacts = json.parse(body); cb(null, contacts); } }); }
that's it.
Comments
Post a Comment