GithubHelp home page GithubHelp logo

meshkdevs / invoketwitterapis Goto Github PK

View Code? Open in Web Editor NEW
6.0 5.0 11.0 213 KB

PowerShell Module to Invoke the Twitter REST APIs and Streaming APIs v1.1. Provides a command to call any Twitter REST API, a command to access any of the Twitter Streaming APIs, and a command to upload media to Twitter.

PowerShell 100.00%

invoketwitterapis's Introduction

InvokeTwitterAPIs

PowerShell Module to Invoke the Twitter REST APIs and Streaming APIs v1.1.

#Before you begin...

You must obtain a Twitter API key, API secret, access token and access token secretmand create a hash with this info that will be passed to the commands

$OAuth = @{'ApiKey' = 'xxxxxxxxxxxxxxxxxxxx'; 'ApiSecret' = 'xxxxxxxxxxxxxxxxx'; 'AccessToken' = 'xxxxxxxxxxxxxxx'; 'AccessTokenSecret' = 'xxxxxxxxxx'}

https://twittercommunity.com/t/how-to-get-my-api-key/7033

#Commands:

#Invoke-TwitterRestMethod

Provides a command to call any Twitter REST API. https://dev.twitter.com/rest/public Pass the desired resource url, list of parameters [key=value], specify the HTTP verb, your $OAuth hash

ex. Invoke-TwitterRestMethod -ResourceURL 'https://api.twitter.com/1.1/direct_messages/new.json' -RestVerb 'POST' -Parameters @{'text' = 'hello, there'; 'screen_name' = 'ruminaterumi' } -OAuthSettings $OAuth

The response will be converted into a ps object

#Invoke-ReadFromTwitterStream

Provides a command to access any of the Twitter Streaming APIs Pass the streaming api url, the path to a file where the responses will be written, the parameters, the http verb, your $OAuth hash, and the number of minutes to read from the stream (or attempt to) -1 is infinite

ex. Invoke-ReadFromTwitterStream -OAuthSettings $OAuth -OutFilePath 'C:\books\foo.txt' -ResourceURL 'https://stream.twitter.com/1.1/statuses/filter.json' -RestVerb 'POST' -Parameters @{'track' = 'foo'} -MinsToCollectStream 1

#Invoke-TwitterMediaUpload

Provides a command to upload media to Twitter. The media id returned can be used to post a status or tweet with that image. This takes the url to upload media, the path to image [jpeg, gif, or png], http verb [POST] ex.

$mediaId = Invoke-TwitterMEdiaUpload -MediaFilePath 'C:\Books\pic.png' -ResourceURL 'https://upload.twitter.com/1.1/media/upload.json' -OAuthSettings $OAuth

Invoke-TwitterRestMethod -ResourceURL 'https://api.twitter.com/1.1/statuses/update.json' -RestVerb 'POST' -Parameters @{'status'='posted pic'; 'media_ids' = $mediaId } -OAuthSettings $OAuth

#Installation

To install this module use this PowerShell command:

iex (New-Object Net.WebClient).DownloadString("https://gist.githubusercontent.com/eshakaya/834f9131cd33176a96ff/raw/dda2727f9b5cb6e1b7d9c650515caf61199c07b5/Install.ps1")

invoketwitterapis's People

Contributors

cosmaioan avatar eshakaya avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

invoketwitterapis's Issues

I can't get it to run :(

I have the following in my ps1 file
Invoke-TwitterMEdiaUpload -MediaFilePath 'c:\users\sebastian\desktop\tmp\twitter\london.jpg' -ResourceURL 'https://upload.twitter.com/1.1/media/upload.json' -OAuthSettings @{'ApiKey' = ''; 'ApiSecret' = ''; 'AccessToken' = ''; 'AccessTokenSecret' = ''}

and I get a Bad Authentication call from twitter. When I debugged the call with fiddler I see no authentication data:

Authorization: OAuth oauth_consumer_key="", oauth_nonce="NjM1Njg5Mjc4MTMzNjU1MjAyMTIzNDUg", oauth_signature="PJ6%2BHDpdj2nftY3CCsKD1diTCt4%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1433341813", oauth_token="", oauth_version="1.0"
User-Agent: Mozilla/5.0 (Windows NT; Windows NT 6.3; en-US) WindowsPowerShell/4.0
Content-Type: multipart/form-data; boundary="fab9a1af-629f-42e1-9bd9-3bc5fb1736af"
Host: upload.twitter.com
Content-Length: 53936
Connection: Keep-Alive

--fab9a1af-629f-42e1-9bd9-3bc5fb1736af
Content-Disposition: file; name="media"; filename=""
Content-Type: image/jpeg

Can you help me out?

Can't run the install script

Hi, when trying to run the install script it failes with an SSL/TLS error. "Can't establish a SSL/TLS secured channel".

Any ideas?

Br
Trond E

Some examples run, but not all

I'm going through the examples at https://github.com/MeshkDevs/InvokeTwitterAPIs; the first one fails, but others work.

The example that fails is:
PS> Invoke-TwitterRestMethod -ResourceURL 'https://api.twitter.com/1.1/direct_messages/new.json' -RestVerb 'POST' -Parameters @{'text' = 'hello, there'; 'screen_name' = 'ruminaterumi' } -OAuthSettings $OAuth

I tried using my own Twitter username, assuming my $OAuth object is unable to authenticate as you, but I would love for you to explain how authentication works, or point me to some clear OAuth documentation.

So, with my username, the command, and error output, is:
PS> Invoke-TwitterRestMethod -ResourceURL 'https://api.twitter.com/1.1/direct_messages/new.json' -RestVerb 'POST' -Parameters @{'text' = 'hello, there'; 'screen_name' = 'dblanchard' } -OAuthSettings $OAuth
Invoke-TwitterRestMethod : The remote server returned an error: (403) Forbidden.
At line:1 char:1

  • Invoke-TwitterRestMethod -ResourceURL 'https://api.twitter.com/1.1/di ...
  •   + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
      + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Invoke-TwitterRestMethod
    
    

My $OAuth object seems to be fine (the redacted values match my actual values):
PS> $OAuth

Name Value


AccessTokenSecret REDACTED
ApiSecret REDACTED
AccessToken REDACTED
ApiKey REDACTED

The next example, with the OutFilePath parameter changed to 'C:\TEMP\books.txt' works fine (I don't have a C:\Books\ directory, and didn't want to create one):
PS> Invoke-ReadFromTwitterStream -OAuthSettings $OAuth -OutFilePath 'C:\TEMP\foo.txt' -ResourceURL 'https://stream.twitter.com/1.1/statuses/filter.json' -RestVerb 'POST' -Parameters @{'track' = 'foo'} -MinsToCollectStream 1

The command does write to foo.txt, and the command does end neatly.

Next I tried the media upload example, first using a URL to an image, which failed for not being able to convert the media type properly, and then using a full path to a local file, which failed for authentication

PS C:\Users\Pingyu Nao> $mediaId = Invoke-TwitterMEdiaUpload -MediaFilePath 'https://twitter.com/i/status/1040690882083737601' -ResourceURL 'https://upload.twitter.com/1.1/media/upload.json' -OAuthSettings $OAuth
Invoke-TwitterMediaUpload : Cannot process argument transformation on parameter 'MediaFilePath'. Cannot convert value "https://twitter.com/i/status/1040690882083737601" to type "System.IO.FileInfo". Error: "The
given path's format is not supported."
At line:1 char:53

  • ... diaFilePath 'https://twitter.com/i/status/1040690882083737601' -Resou ...
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidData: (:) [Invoke-TwitterMediaUpload], ParameterBindingArgumentTransformationException
    • FullyQualifiedErrorId : ParameterArgumentTransformationError,Invoke-TwitterMediaUpload

PS C:\Users\Pingyu Nao> $mediaId = Invoke-TwitterMEdiaUpload -MediaFilePath 'C:\TEMP\meme.jpg' -ResourceURL 'https://upload.twitter.com/1.1/media/upload.json' -OAuthSettings $OAuth
Invoke-TwitterMEdiaUpload : FAILED to reach 'https://github.com/MeshkDevs/InvokeTwitterAPIs/archive/master.zip': {"errors":[{"code":215,"message":"Bad Authentication data."}]}
At line:1 char:12

  • $mediaId = Invoke-TwitterMEdiaUpload -MediaFilePath 'C:\TEMP\meme.jpg ...
  •        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
    • FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Invoke-TwitterMediaUpload

Invoke-RestMethod : {"errors":[{"code":215,"message":"Bad Authentication data."}]}
At C:\Users\Pingyu Nao\Documents\WindowsPowerShell\Modules\InvokeTwitterAPIs\InvokeTwitterAPIs.psm1:183 char:24

  • ... $response = Invoke-RestMethod -Uri $ResourceURL -Body $z -Method Post ...
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    • FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

I'll keep working through it, but I'd love any guidance you can give me.

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.