Node.js 如何从flickr获取收藏夹

Node.js 如何从flickr获取收藏夹,node.js,flickr,Node.js,Flickr,我正在使用Node.js从flickr中的用户那里获取收藏夹照片列表,我知道还有其他方法可以获取收藏夹的公共列表,而且这种方法对我来说很好,但是使用这种方法,flickrAPI会返回此错误 {"stat":"fail", "code":98, "message":"Invalid auth token"} 这是我的代码: var util = require('util'), http = require('http'), keys = require(__dirname

我正在使用Node.js从flickr中的用户那里获取收藏夹照片列表,我知道还有其他方法可以获取收藏夹的公共列表,而且这种方法对我来说很好,但是使用这种方法,flickrAPI会返回此错误

{"stat":"fail", "code":98, "message":"Invalid auth token"}
这是我的代码:

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 to the url.
url = url + '&api_sig=' + encodeURIComponent(api_signature);

http.get(url, function(res) {});
}
在下面一行

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);
我认为在此之前您还没有初始化
userInfo
对象,这导致了与
userInfo.oauth\u令牌相关的认证错误

更新为问题编辑 在调用api之前,请确保
userInfo
具有
oauth\u token
属性

if(typeof(userInfo)!="undefined" && typeof(userInfo.oauth_token)!="undefined" && userInfo.oauth_token!="") {

    //code for api call

}

userInfo是参数,我已经更新了代码以反映我的原始代码。