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.