问题
I need a signature for my first request to twitter :
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.
I have only call back Url, consumer_key. I have created nonce and timestamp. I need signature.
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"
回答1:
I think twitter has a nicely written document on creating a signature. https://dev.twitter.com/docs/auth/creating-signature
Check it out...
Edit: I noticed your oauth_* parameters are not in order. Don't forget to get them in order.
回答2:
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");
then generating signature like this :
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 :)
来源:https://stackoverflow.com/questions/19699721/how-to-create-signature-for-twitter-in-salesforce-and-what-are-the-steps-for-sig