我正在使用Node.js来获取用户在 flickr 中的收藏照片列表,我知道还有其他方法可以获取收藏夹的公开列表,并且该工作正常我,但使用此 flickr API会返回此错误。
{"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) {});
}
答案 0 :(得分: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.just之前确保userInfo
具有oauth_token
属性,就像您可以将api调用包含在支票中一样
if(typeof(userInfo)!="undefined" && typeof(userInfo.oauth_token)!="undefined" && userInfo.oauth_token!="") {
//code for api call
}