skip to Main Content

I want to get post information of a specific user from Twitter from PowerShell.

The command used to get post information is “Invoke-RestMethod”.

Please let me know the OAuth authentication procedure required at that time.

The following information has been obtained.

  • ・API key
  • ・API secret key
  • ・Access token
  • ・Access token secret

2

Answers


  1. The easiest way to access the twitter api in PowerShell is to use one of the modules, that wrap around it, like MyTwitter.

    A detailed description on how to get started with the this module can be found here: https://adamtheautomator.com/twitter-module-powershell/.

    If you have to avoid external modules, you can use Invoke-RestMethod to call the api directly.

    The article linked above describes, how to create an access token and the api reference can be found here: https://developer.twitter.com/en/docs/tweets/search/api-reference

    Login or Signup to reply.
  2. Another option is PSTwitterAPI. It provides a function for +125 Twitter API endpoints.

    Import-Module PSTwitterAPI
    
    $OAuthSettings = @{
      ApiKey = ''
      ApiSecret = ''
      AccessToken = ''
      AccessTokenSecret = ''
    }
    
    Set-TwitterOAuthSettings @OAuthSettings
    
    # Use one of the API Helpers provided:
    $TwitterUser = Get-TwitterUsers_Lookup -screen_name 'mkellerman'
    
    # Send tweet to your timeline:
    Send-TwitterStatuses_Update -status "Hello World!! @mkellerman #PSTwitterAPI"
    
    # Send DM to a user:
    $Event = Send-TwitterDirectMessages_EventsNew -recipient_id $TwitterUser.Id -text "Hello @$($TwitterUser.screen_name)!! #PSTwitterAPI"
    
    # Get the tweets you would see on your timeline:
    $TwitterStatuses = Get-TwitterStatuses_HomeTimeline -count 100
    
    # Get tweets from someone elses timeline (what they tweeted):
    $TwitterStatuses = Get-TwitterStatuses_UserTimeline -screen_name 'mkellerman' -count 400
    
    # Search for tweets:
    $Tweets = Get-TwitterSearch_Tweets -q '#powershell' -count 400
    

    For more info: https://github.com/mkellerman/PSTwitterAPI

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search