Hello @sachin gupta ,
Thanks for the question and using MS Q&A platform
Reading the Twitter API Documentation.
Reference: https://developer.twitter.com/en/docs/authentication/oauth-1-0a
My understanding is that - You must sign each API request by passing keys and the token you have if you are authenticating using OAUTH 1.0a.
You will have to create a pass with the OAUTH signature. And pass it along the other headers.
oauth_signature="OAUTH_SIGNATURE"
authorization= OAuth
oauth_consumer_key="CONSUMER_API_KEY"
oauth_nonce="OAUTH_NONCE"
oauth_signature_method="HMAC-SHA1"
oauth_timestamp="OAUTH_TIMESTAMP"
oauth_token="ACCESS_TOKEN"
oauth_version="1.0"'
You can manually generate the OAUTH Signature by following the steps mentioned here - you will need client key,client secret,access token,access token secret.
I am thinking that you could make use of an Azure Function / Batch service to generate the OAUTH Signature automatically. Sample PS Script to generate a OAUTH Signature to update a status would look like below:
status = [System.Uri]::EscapeDataString("My ");
$oauth_consumer_key = "<your client key>";
$oauth_consumer_secret = "< your client secret>";
$oauth_token = "<your auth token>";
$oauth_token_secret = "< your auth token secret>";
$oauth_nonce = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes([System.DateTime]::Now.Ticks.ToString()));
$ts = [System.DateTime]::UtcNow - [System.DateTime]::ParseExact("01/01/1970", "dd/MM/yyyy", $null).ToUniversalTime();
$oauth_timestamp = [System.Convert]::ToInt64($ts.TotalSeconds).ToString();
$signature = "POST&";
$signature += [System.Uri]::EscapeDataString("http://api.twitter.com/1/statuses/update.json") + "&";
$signature += [System.Uri]::EscapeDataString("oauth_consumer_key=" + $oauth_consumer_key + "&");
$signature += [System.Uri]::EscapeDataString("oauth_nonce=" + $oauth_nonce + "&");
$signature += [System.Uri]::EscapeDataString("oauth_signature_method=HMAC-SHA1&");
$signature += [System.Uri]::EscapeDataString("oauth_timestamp=" + $oauth_timestamp + "&");
$signature += [System.Uri]::EscapeDataString("oauth_token=" + $oauth_token + "&");
$signature += [System.Uri]::EscapeDataString("oauth_version=1.0&");
$signature += [System.Uri]::EscapeDataString("status=" + $status);
$signature_key = [System.Uri]::EscapeDataString($oauth_consumer_secret) + "&" + [System.Uri]::EscapeDataString($oauth_token_secret);
$hmacsha1 = new-object System.Security.Cryptography.HMACSHA1;
$hmacsha1.Key = [System.Text.Encoding]::ASCII.GetBytes($signature_key);
$oauth_signature = [System.Convert]::ToBase64String($hmacsha1.ComputeHash([System.Text.Encoding]::ASCII.GetBytes($signature)));
Note : You may need to use the same timestamp and oauth nonce as used in generating the signature in the headers of the WebActivity.
Alternatively, you could make use of OAUTH 2.0 -This is app only authentication - meaning there is no context of user as opposed to the above method.
Reference : https://developer.twitter.com/en/docs/authentication/oauth-2-0/bearer-tokens
You could get the bearer token from the portal by following the below steps:
- Login to your Twitter account on developer.twitter.com.
- Navigate to the "Projects and Apps overview" page.
- Click on the key icon of one of your developer Apps to open the "keys and tokens" page.
- Under the "Authentication tokens" section, click "Generate" next to Bearer Token.
Now with this token, you could invoke a web request - with the header as below in the WebActivity:
Authorization: Bearer <Generated Token>
Hope this will help. Please let us know if any further queries.
------------------------------
- Please don't forget to click on
or upvote
button whenever the information provided helps you. Original posters help the community find answers faster by identifying the correct answer. Here is how
- Want a reminder to come back and check responses? Here is how to subscribe to a notification
- If you are interested in joining the VM program and help shape the future of Q&A: Here is how you can be part of Q&A Volunteer Moderators