我想从我的节点服务器向yelp.com提出请求,但我需要在我的请求中使用OAuth.getParameterMap
和其他OAuth函数。我想知道是否有任何关于我需要的功能的npm?
到目前为止,这是我的代码:
app.post('/yelpApp', function (req, res)
{
var auth = {
consumerKey: conKey,
consumerSecret: conSec,
accessToken: accTok,
accessTokenSecret: accTokSec,
serviceProvider: {
signatureMethod: "HMAC-SHA1"
}
};
var terms = 'food';
var near = 'London';
var accessor = {
consumerSecret: auth.consumerSecret,
tokenSecret: auth.accessTokenSecret
};
parameters = [];
parameters.push(['term', terms]);
parameters.push(['location', near]);
parameters.push(['callback', 'cb']);
parameters.push(['oauth_consumer_key', auth.consumerKey]);
parameters.push(['oauth_consumer_secret', auth.consumerSecret]);
parameters.push(['oauth_token', auth.accessToken]);
parameters.push(['oauth_signature_method', 'HMAC-SHA1']);
var message = {
'action': 'http://api.yelp.com/v2/search',
'method': 'GET',
'parameters': parameters
};
//can't use these OAuth functions on server
OAuth.setTimestampAndNonce(message);
OAuth.SignatureMethod.sign(message, accessor);
var parameterMap = OAuth.getParameterMap(message.parameters);
parameterMap.oauth_signature = OAuth.percentEncode(parameterMap.oauth_signature)
$.ajax(
{
'url': message.action,
'data': parameterMap,
'cache': true,
'dataType': 'json',
'success': function(data, textStats, XMLHttpRequest)
{
res.send(JSON.stringify({foo: data}));
}
});
});