问题描述
我的第一个 twitter 请求需要签名:
I need a signature for my first request to twitter :
我的代码为此 URL 创建一个 Post 请求 https://api.twitter.com/oauth/request_token 并且我必须设置一个标题,下面提到我需要在其中签名.
My code create a Post request for this end Url https://api.twitter.com/oauth/request_token and I have to set a header which is mention below in which I need signature.
我只有回调 Url,consumer_key.我已经创建了 nonce 和时间戳.我需要签名.
I have only call back Url, consumer_key. I have created nonce and timestamp. I need signature.
授权头:OAuth oauth_nonce="XXXXXXXXX", oauth_callback="XXXX", oauth_signature_method="HMAC-SHA1", oauth_timestamp="XXXXXX", oauth_consumer_key="XXXXXX", oauth_signature="如何创建这个", oauth"
Authorization Header:OAuth oauth_nonce="XXXXXXXXX", oauth_callback="XXXX", oauth_signature_method="HMAC-SHA1", oauth_timestamp="XXXXXX", oauth_consumer_key="XXXXXX", oauth_signature="HOW I CREATE THIS", oauth_version="1.0"
推荐答案
您可以使用 oauth 模块 https://github.com/ciaranj/node-oauth
You can use oauth module https://github.com/ciaranj/node-oauth
var oauth=require('oauth');
var consumer = new oauth.OAuth(
"https://twitter.com/oauth/request_token", "https://twitter.com/oauth/access_token",
_twitterConsumerKey, _twitterConsumerSecret, "1.0A", "http://127.0.0.1:8080/sessions/callback", "HMAC-SHA1");
然后像这样生成签名:
var parameters = consumer._prepareParameters("user_access_token", "user_access_token_secret", "http_method", "request_url");
var headers = consumer._buildAuthorizationHeaders(parameters);
参数数组包含签名,如果需要,您也可以构建授权头.希望它有帮助:)
parameters array contains signature, also you can build authorization headers if needed. Hope it helps :)
这篇关于如何在 Salesforce 中为 Twitter 创建签名以及创建签名的步骤是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!