mkellerman / pstwitterapi Goto Github PK
View Code? Open in Web Editor NEWPSTwitterAPI - a PowerShell module for the Twitter API
Home Page: https://mkellerman.github.io/Introducing_PSTwitterAPI/
PSTwitterAPI - a PowerShell module for the Twitter API
Home Page: https://mkellerman.github.io/Introducing_PSTwitterAPI/
I'm trying to use Send-TwitterAccount_UpdateProfileBanner
to update my account banner:
$Image = [Convert]::ToBase64String((Get-Content .\TwitterBanner.png -Encoding Byte))
Send-TwitterAccount_UpdateProfileBanner -banner $Image
Naturally, that Image string is HUGE, as I'm trying to send a 1500x500 image (the recommended size for one of these banners) that's 101 KB on disk.
When run, I get back
Get-OAuthParameters : Exception calling "EscapeDataString" with "1" argument(s): "Invalid URI: The Uri string is too long."
At C:\Users\joshuak\Documents\WindowsPowerShell\Modules\PSTwitterAPI\0.0.7\public\Invoke-TwitterAPI.ps1:26 char:24
+ $OAuthParameters = Get-OAuthParameters @OAuthParameters_Params
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Get-OAuthParameters
Invoke-RestMethod : Cannot bind parameter 'Method' to the target. Exception setting "Method": "Cannot convert null to type "Microsoft.PowerShell.Commands.WebRequestMethod" due to enumeration
values that are not valid. Specify one of the following enumeration values and try again. The possible enumeration values are "Default,Get,Head,Post,Put,Delete,Trace,Options,Merge,Patch"."
At C:\Users\joshuak\Documents\WindowsPowerShell\Modules\PSTwitterAPI\0.0.7\public\Invoke-TwitterAPI.ps1:34 char:23
+ Invoke-RestMethod @RestMethod_Params
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [Invoke-RestMethod], ParameterBindingException
+ FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
Looks like the entire image payload is being encoded as part of the URI... which if my understanding of that class is right is capped at 2048 characters? I've tried halving the size of the image, but it's still too long.
I think that shipping this data up as a JSON body on Invoke-RESTMethod
would get it up there (I was playing around with this a little, but mucked up the authentication side of things lol)
When installing the current version during Azure Pipelines release, it's necessary to use the -Force parameter:
Install-PackageProvider -Name PSTwitterAPI -Force -Scope CurrentUser
The build server is stateless so the module hasn't been installed before.
In this case, -Force along with no previous module installation, results in the error:
During module import on Exporting function Set-TwitterOAuthSettings
"No OAuthSettings was found. Use 'Set-TwitterOAuthSettings' to set PSTwitterAPI ApiKey & Token."
Could you remove the throw on the next update so that it's possible to use the PS Gallery version again?
Otherwise the module is fantastic... saved me a tonne of time - thanks :)
I might be doing something wrong as the tutorial sadly isn't very detailed but I'm getting an error trying to set up PSTwitterAPI. I installed it just fine and then edited my PowerShell startup script by adding:
Import-Module PSTwitterAPI
$OAuthSettings = @{
"MYAPIKEY" = $env:ApiKey
"MYAPISECRET" = $env:ApiSecret
"MYACCESSTOKEN" = $env:AccessToken
"MYACCESSTOKENSECRET" =$env:AccessTokenSecret
}
Set-TwitterOAuthSettings @OAuthSettings
The first three keys seem to check out but the last one returns an error akin to "Invalid value for AccessTokenSecret, no value was assigned". I had to paraphrase as my Windows is set to German. Did I add the keys wrong? I'm new to PowerShell.
EDIT: I thought I would add the exact error message in German:
Set-TwitterOAuthSettings : Es wurde kein Parameter gefunden, der dem Parameternamen "MYACCESSTOKENSECRET" entspricht.
A better translation would be:
There is no parameter that matches the parameter-name "MYACCESSTOKENSECRET". It shows the actual token there to clarify but of course I won't post that online.
Provides the wrong function name to guide the user to set their OAuthSettings.
Should be Set-TwitterOAuthSettings
Currently, I'm using this command to generate the list of CmdletBindingParameters that is generated by using [CmdletBinding()]. We want to eliminate this when using the parameters for our TwitterAPI generated by the APIHelper.
$Script:CmdletBindingParameters = (Get-Command 'Get-Culture').Parameters.Keys
Needs to be replaced by static list to improve loading speeds.
Currently takes ~2.5 seconds to load.
Hi,
Now when you create an API Account on twitter, it is by default a Essential Account with only v2 API
https://developer.twitter.com/en/docs/twitter-api/getting-started/about-twitter-api#v2-access-level
There is some plan to support/upgrade to v2 API ?
Any idea why I am getting this error calling Send-TwitterDirectMessages_EventsNew?
Code:
$TwitterUser = Get-TwitterUsers_Lookup -screen_name 'chinhdo'
$Event = Send-TwitterDirectMessages_EventsNew -recipient_id $TwitterUser.Id -text "Hello !!"
The Get-TwitterUsers_Lookup method works fine. But the Send-TwitterDirectMessages_EventsNew errored out with the below. I did configure the app permissions to allow Read + Write + Direct Messages.
Invoke-RestMethod : {"errors":[{"code":215,"message":"Bad Authentication data."}]}
At C:\Program Files\WindowsPowerShell\Modules\PSTwitterAPI\0.0.8\public\Invoke-TwitterAPI.ps1:34 char:5
+ Invoke-RestMethod @RestMethod_Params
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExceptio
n
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
WARNING: Throttling for -1626964553.70296 seconds.
Start-Sleep : Cannot validate argument on parameter 'Seconds'. The -1626964554 argument is less than the minimum allowed
range of 0. Supply an argument that is greater than or equal to 0 and then try the command again.
At C:\Program Files\WindowsPowerShell\Modules\PSTwitterAPI\0.0.8\public\Get-TwitterOAuthSettings.ps1:33 char:38
+ Start-Sleep -Seconds $SleepSeconds
+ ~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Start-Sleep], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.StartSleepCommand
Thanks
Recreating issue #29, to start the conversation about this Module in particular.
I will remove the '_' from the function names in the next PR.
Test:
Import-Module
Test-ModuleManifest
Validated exported functions
Invoke-ScriptAnalyzer on each file
Hello again,
I wrote a powershell wrapper (to explain the next format) that executes fine however the tweet ID remain zero and I am want it for further actions like retweet etc.. Am I missing something?
protected override Task EndProcessingAsync(){
return TwitterContext.TweetAsync(Status,_medias.Select(media => media.MediaID)).ToObservable()
.HandleErrors(this)
.WriteObject(this)
.ToTask();
}
Type : User
ID : 0
UserID : 0
ScreenName :
SinceID : 0
MaxID : 0
Count : 0
Cursor : 0
IncludeRetweets : False
ExcludeReplies : False
IncludeEntities : False
IncludeUserEntities : False
IncludeMyRetweet : False
IncludeAltText : False
OEmbedUrl :
OEmbedMaxWidth : 0
OEmbedHideMedia : False
OEmbedHideThread : False
OEmbedOmitScript : False
OEmbedAlign : None
OEmbedRelated :
OEmbedLanguage :
CreatedAt : 4/23/2020 11:32:57 AM
StatusID : 1253285727498010624
Text : The A��-������������������������� #XpandPwsh PowerShell CmdLet:
Filter out warnings for a PackageReference.
Wiki… https://t.co/r6JRAEQdfT
FullText :
ExtendedTweet : LinqToTwitter.Status
Source : <a href="http://www.expandframework.com" rel="nofollow">MSBuild Teamcity</a>
Truncated : True
DisplayTextRange :
TweetMode : Compat
InReplyToStatusID : 0
InReplyToUserID : 0
FavoriteCount : 0
Favorited : False
InReplyToScreenName :
User : LinqToTwitter.User
Users : {}
Contributors : {}
Coordinates : LinqToTwitter.Coordinate
Place : LinqToTwitter.Place
Annotation : LinqToTwitter.Annotation
Entities : LinqToTwitter.Entities
ExtendedEntities : LinqToTwitter.Entities
TrimUser : False
IncludeContributorDetails : False
RetweetCount : 0
Retweeted : False
PossiblySensitive : False
RetweetedStatus : LinqToTwitter.Status
CurrentUserRetweet : 0
IsQuotedStatus : False
QuotedStatusID : 0
QuotedStatus : LinqToTwitter.Status
Scopes : {}
WithheldCopyright : False
WithheldInCountries : {}
WithheldScope :
MetaData : LinqToTwitter.StatusMetaData
Lang : en
Map : False
TweetIDs :
FilterLevel : None
EmbeddedStatus :
CursorMovement :
Example:
Get-TwitterUsers_Lookup
There is a max number of IDs you can provide per call.
I have this in script:
$ErrorActionPreference = 'Continue'
try {
Import-Module PSTwitterAPI
Set-TwitterOAuthSettings -ApiKey 'xx' -ApiSecret 'xx' -AccessToken 'xx' -AccessTokenSecret 'xx'
...
this causes error:
No OAuthSettings was found. Use 'Set-TwitterOAuthSettings' to set PSTwitterAPI ApiKey & Token.
At C:\Program Files\WindowsPowerShell\Modules\PSTwitterAPI\0.0.7\public\Get-TwitterOAuthSettings.ps1:35 char:9
Throw "No OAuthSettings was found. Use 'Set-TwitterOAuthSetti ...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
looks like erroraction part in Set-TwitterOAuthSettings in script is being ignored.
...
If ($OAuthSettings = Get-TwitterOAuthSettings -AccessToken $AccessToken -ErrorAction SilentlyContinue)
...
If I remove throw from Get-TwitterOAuthSettings, it works.
Set-TwitterOAuthSettings works when run on command line..?
Hi
I hit an issue when using the module in Azure DevOps pipelines
I forked the repo and did a (quite a horrible) workaround here:
https://github.com/whiteken/NSTrainTime/tree/master/PSTwitterAPI/0.0.7
Due to scoping on the build agent it wasn't able to find the script variable for Oauth settings so I dump it out to clixml instead.
Could a condition to chose this for AZDO be included in the update?
$file = "D:\OneDrive\Desktop\images\New_folder\Abedour.jpg"
$length = (get-item $file).Length
Send-TwitterMedia_Upload -command INIT -total_bytes $length -media_type image/jpeg
this returns the media.id, but I cant see the syntax for Send-TwitterStatuses_UpdateWithMedia to actually upload and post?
Send-TwitterBlocks_Create -screen_name $screenname
Some other commands works fine so I know the oauth is working.
I get this error
BadRequest
{"errors":[{"code":215,"message":"Bad Authentication data."}]}
at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request)
at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()
Hi,
There is a rogue 'POST' in the $ResourceUrl for this function, causing it to error on execution.
PS C:\Users\Martin> Get-TwitterBlocks_Ids
ids : {1129359659653971969, 1180924045157687296}
next_cursor : 0
next_cursor_str : 0
previous_cursor : 0
previous_cursor_str : 0
total_count :
PS C:\Users\Martin> Send-TwitterBlocks_Destroy -user_id 1180924045157687296
Invoke-RestMethod : Invalid URI: The hostname could not be parsed.
At D:\Users\Martin\Documents\WindowsPowerShell\Modules\PSTwitterAPI\0.0.7\public\Invoke-TwitterAPI.ps1:34 char:5
+ Invoke-RestMethod @RestMethod_Params
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Invoke-RestMethod], UriFormatException
+ FullyQualifiedErrorId : System.UriFormatException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
PS C:\Users\Martin>
Thanks,
Martin
For a project at school I'll be using this API which will make my life a lot easier. Whilst setting up the API I came across a Problem. I am a rookie if it comes to PowerShell so this is probably an easy fix but I can't seem to find it. When I want to import the module I get the error that it cannot be loaded because running scripts is disabled on this system.
Can someone tell me what i need to do exactly?
In addition to the project, can someone tell me how i can search for tweets using a specific hashtag?
Thank you in advance
Toon Staes
In the function Invoke-TwitterAPI, we require 2 parameters:
Name | Example |
---|---|
$Resource | /statuses/update |
$ResourceUrl | https://api.twitter.com/1.1/statuses/update.json |
$Resource is used to find the RateLimitStatus on that resource. And $ResourceUrl is used to build the OAuthSettings.
But some resources are like this:
[string]$Resource = '/geo/id/:place_id'
[string]$ResourceUrl = 'https://api.twitter.com/1.1/geo/id/:place_id.json'
And I need to replace :place_id in the ResourceUrl with the actual value of the place_id parameter.
[string]$ResourceUrl = https://api.twitter.com/1.1/geo/id/df51dec6f4ee2b2c.json
I suspect that I will need to generate the $Resource from the $ResourceUrl.
If I don't find a resource with the full text, then look for partial match.
I would like to have to only supply one parameter, so less parameters are required to do manual Invoke-TwitterAPI commands.
Get-TwitterSearch_Tweets
I suspect more are missing.
Just running through the code and noticed a nonce creation, was just logging an issue that we can probably switch it over to a RijndaelManaged implementation without too much trouble and a lot more nonce'y'ness.
I'd be glad to PR this.
https://github.com/mkellerman/PSTwitterAPI/blob/master/PSTwitterAPI/private/Get-OAuthParameters.ps1#L14
https://docs.particular.net/nservicebus/security/generating-encryption-keys
It is a standard practice that no _
or -
(other than between Verb-Noun
) are used in function names
Therefore this issue is to raise about removing them to fall inline with standard PowerShell Practices
This link is no longer available:
https://twittercommunity.com/t/how-to-get-my-api-key/7033 <--- NO BUENO
That whole process has changed, you now need to register as a developer https://developer.twitter.com/en/apply-for-access and create an app in there https://developer.twitter.com/en/apps/create to get keys
The above explanation is comes from the link below:
https://twittercommunity.com/t/twitter-oauth-keys/119836
Seems like the Update-ModuleManifest changes the value of my FunctionsToExport in the manifest.
I believe there is a parameter tweet_extended which can be set to yes/no but I am not sure how to pull and fix that. It might also be a matter of requesting full_text vs text according to what I have read. Is it simply a matter of updating the API JSON file?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.