test the micros

sachin gupta 376 Reputation points
2021-11-11T17:09:06.643+00:00

test to send the question

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,625 questions
{count} votes

4 answers

Sort by: Most helpful
  1. svijay-MSFT 5,256 Reputation points Microsoft Employee Moderator
    2021-11-12T16:11:26.557+00:00

    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:

    1. Login to your Twitter account on developer.twitter.com.
    2. Navigate to the "Projects and Apps overview" page.
    3. Click on the key icon of one of your developer Apps to open the "keys and tokens" page.
    4. 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 130616-image.png or upvote 130671-image.png 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

  2. Sachin 26 Reputation points
    2021-11-14T18:04:59.46+00:00

    @svijay-MSFT ... I am able to generate the oAuth signature and oauth nounce in power shell. Now When I used all the credentials in the Web Activity header, I am still not able to get authorize the endpoint

    PFA, the web activity Authorization header and the credentials149059-webactivity-adf.png149049-webactivity-error.png which I sent

    OAuth oauth_consumer_key=XXX&
    oauth_token=XXXX&
    oauth_consumer_secret=XXX&
    oauth_token_secret=XXX&
    oauth_signature_method=HMAC-SHA1&
    oauth_timestamp=1636911760&
    oauth_nonce=5t1Ev81dDKW&
    oauth_version=1.0&
    oauth_signature=XXXX%3D

    Please guide me what I am doing wrong here.

    Thanks

    0 comments No comments

  3. Sachin 26 Reputation points
    2021-11-14T23:09:23.597+00:00

    @svijay-MSFT for an update, i changed the way of passing the parameters like below in the web Activity header - Authorization.

    OAuth oauth_consumer_key="XXX",oauth_consumer_secret="XXX",oauth_nonce="NjM3NzIXXX",oauth_signature="SM0bFgS4MoJn25RzChyU55j58rA%3D",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1636908976",oauth_token="XXX",oauth_token_secret="XXX",oauth_version="1.0"

    This time I got different error

    {"errors":[{"message":"Could not authenticate you","code":32}]}


  4. sachin gupta 376 Reputation points
    2021-11-15T17:44:44.813+00:00

    @svijay-MSFT ... i have made sure all the points you mentioned and still getting the same error. This is the endpoint which I am trying. I gave this Endpoint in the Power shell script that you have provided to generate the Oauth Signature.

    Ads API -

    https://ads-api.twitter.com/10/stats/accounts/XXXX?entity=PROMOTED_TWEET&entity_ids=XXXX&start_time=2017-05-19&end_time=2017-05-26&granularity=TOTAL&placement=ALL_ON_TWITTER&metric_groups=ENGAGEMENT

    Power shell Script which you sent
    $signature = "POST&";
    $signature += [System.Uri]::EscapeDataString("**http://api.twitter.com/1/statuses/update.json**") + "&";
    $signature += [System.Uri]::EscapeDataString("oauth_consumer_key=" + $oauth_consumer_key + "&");

    Script which I created

    $signature = "GET&";  
    $signature += [System.Uri]::EscapeDataString("https://ads-api.twitter.com/10/stats/accounts/XXXX?entity=PROMOTED_TWEET&entity_ids=XXXX&start_time=2017-05-19&end_time=2017-05-26&granularity=TOTAL&placement=ALL_ON_TWITTER&metric_groups=ENGAGEMENT") + "&";  
    

    is this the right way to generate the signature for any twitter API which requires OAuth 1.0 a authentication?

    Requesting you to please respond asap. I am really stuck in it.
    Thank you


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.