我尝试过搜索和使用多个oauth模块,但我无法让它工作。这让我最接近(从https://arian.io/how-to-use-yelps-api-with-node/复制的代码)
var yelp_search = function(input_parameters, call_back) {
var httpRequest = "GET";
var fileName = "./secret-config.json";
var config = require(fileName);
var url = 'http://api.yelp.com/v2/search';
console.log(config.ConsumerKey);
var search_parameters = {
callback : "cb",
location: "Sunnyvale, CA"
}
var oauth_parameters = {
oauth_consumer_key : config.ConsumerKey,
oauth_token : config.Token,
oauth_nonce : n(),
oauth_timestamp : n().toString().substr(0,10),
oauth_signature_method : 'HMAC-SHA1',
oauth_version : '1.0',
};
var parameters = _.assign(search_parameters, input_parameters, oauth_parameters);
var consumerSecret = config.consumerSecret;
var tokenSecret = config.tokenSecret;
var signature = oauthSignature.generate(httpRequest, url, parameters, consumerSecret, tokenSecret, { encodeSignature: false});
parameters.oauth_signature = signature;
var parameterURL = qs.stringify(parameters);
var apiURL = url+'?'+parameterURL;
console.log(apiURL);
request(apiURL, function(error, response, body){
return callback(error, response, body);
});
};
然而,我收到此错误:"错误":{"文字":"签名无效"," id":& #34; INVALID_SIGNATURE","说明":"无效的签名。预期的签名基本字符串:
我不知道自己做错了什么!一切似乎都很好,但我看不出我做错了什么......