I am trying to get the contact list from yahoo through Yahoo OAuth 2.0 Authentication
I get the correct information of the user. But whenever I try to get the contacts list I get the error token_expired
. This is the url that i use https://social.yahooapis.com/v1/user/' + user.guid + '/contacts'
The guid is correct. My code is as follows:
app.get('/contacts', function(req, res) {
if (!req.session.user) {
return res.redirect('/auth/yahoo');
}
var user = req.session.user;
var contactsApiUrl = 'https://social.yahooapis.com/v1/user/' + user.guid + '/contacts';
console.log(user);
var options = {
url: contactsApiUrl,
headers: { Authorization: 'Bearer ' + user.accessToken },
rejectUnauthorized: false,
json: true
};
request.get(options, function(err, response, body) {
console.log(body);
var contacts = body.contacts.contact.map(function(contact) {
return contact.fields[0];
});
res.render('contacts', {
title: 'Contacts',
user: req.session.user,
contacts: contacts
});
});
});
My app has permissions to:
1- Profile: Read/Write Public and Private
2- Contacts: Read
The access token should expire in 3600 seconds but it expires instantly.
I am using node.js (express.js) for this purpose. I have searched this issue and many people suggested refreshing the access Token, but my app doesn't get the contact list even the first time I try to get it. So, I am guessing there is some other issue. I know I haven't placed exception handling yet and app crashes when no information is received but that is not the issue here.