Node.js   发布时间:2022-04-24  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了node.js – 如何在Node中发送OAuth请求大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我想访问node.js中的WS REST API.我有oauth_consumer_key和oauth_token以及API端点. oauth_signature_method是HMAC-SHA1.

如何在Node中发送OAuth请求?@H_772_3@

是否有模块/库来生成请求标头?我期望的功能如下:@H_772_3@

var httprequest = createrequest(url,method,consumer_key,token);

>更新10/14/2012.添加解决方案.@H_772_3@

我正在使用下面的代码.@H_772_3@

var OAuth = require('oauth').oAuth;

consumer = new OAuth('http://term.ie/oauth/example/request_token.PHP','http://term.ie/oauth/example/access_token.PHP','key','secret','1.0',null,'HMAC-SHA1');

// Get the request token                    
consumer.getOAuthrequestToken(function(err,oauth_token,oauth_token_secret,results ){
    console.log('==>Get the request token');
    console.log(arguments);
});


// Get the authorized access_token with the un-authorized one.
consumer.getOAuthAccessToken('requestkey','requestsecret',function (err,results){
    console.log('==>Get the access token');
    console.log(arguments);
});

// Access the protected resource with access token
var url='http://term.ie/oauth/example/echo_api.PHP?method=foo&bar=baz';
consumer.get(url,'accesskey','accesssecret',data,responsE){
    console.log('==>Access the protected resource with access token');
    console.log(err);
    console.log(data);
});

解决方法

大佬总结

以上是大佬教程为你收集整理的node.js – 如何在Node中发送OAuth请求全部内容,希望文章能够帮你解决node.js – 如何在Node中发送OAuth请求所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。