node.js - How to get the favorites from flickr -


i working on node.js list of favorites photos user in flickr, know there other method public list of favorites, , 1 works fine me, using flickr api return me error.

{"stat":"fail", "code":98, "message":"invalid auth token"} 

this code:

var util  = require('util'), http      = require('http'), keys      = require(__dirname + '/../oauth/flickrkeys'), utilities = require(__dirname + '/utilities');  var getphotos = function(userinfo, callback) { var requestresponse, parameters, requestpoint, url, tohash, secretkey, api_signature, method = "flickr.favorites.getlist", format = "json"; requestpoint = 'http://api.flickr.com/services/rest/';  url = requestpoint      + '?api_key=' + keys.clave     + '&auth_token=' + userinfo.oauth_token     + '&format=' + format     + '&method=' + method     + '&min_fave_date=' + userinfo.min_fave_date     + '&nojsoncallback=1'     + '&user_id=' + encodeuricomponent(userinfo.user_nsid);  parameters = 'api_key=' + keys.clave     + '&auth_token=' + userinfo.oauth_token     + '&format=' + format     + '&method=' + method     + '&min_fave_date=' + userinfo.min_fave_date     + '&nojsoncallback=1'     + '&user_id=' + encodeuricomponent(userinfo.user_nsid); tohash = 'get&'     + encodeuricomponent(requestpoint) + '&'     + encodeuricomponent(parameters);  // coding hash. secretkey = keys.secreto + "&" + userinfo.oauth_token_secret; api_signature = utilities.generateflickrsignaturehex(tohash, secretkey);  // adding api signature url. url = url + '&api_sig=' + encodeuricomponent(api_signature);  http.get(url, function(res) {}); } 

at below line

url = requestpoint  + '?api_key=' + keys.clave + '&auth_token=' + userinfo.oauth_token + '&format=' + format + '&method=' + method + '&min_fave_date=' + userinfo.min_fave_date + '&nojsoncallback=1' + '&user_id=' + encodeuricomponent(userinfo.user_nsid); 

i think haven't initialized userinfo object before this, causes mentioned authentication error related userinfo.oauth_token

updated question edit

make sure userinfo has oauth_token attribute before calling api.just can wrap api call inside check like

if(typeof(userinfo)!="undefined" && typeof(userinfo.oauth_token)!="undefined" && userinfo.oauth_token!="") {      //code api call  } 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -