0

I am working on Node.js to get the list of favorites photos from a user in flickr, I know there is other method to get the public list of favorites, and that one works fine to me, but using this the flickr API return me this error.

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

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

http.get(url, function(res) {});
}
4

1 回答 1

0

在下一行

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_token

更新为问题编辑

在调用 api 之前确保userInfo有一个oauth_token属性。就像你可以将 api 调用包装在一个检查中一样

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

    //code for api call

}
于 2013-08-23T19:12:24.537 回答