Releases: Fallenstedt/twitter-stream
v0.4.2
v0.4.1
0.4.1
Summary
Changes were made to StartStream
function. You can now request additional data from each tweet with a NewStreamQueryParamsBuilder
Changes to StartStream
Before
Originally, users who start a stream would need to pass in query params as a string. Users had to ensure they included a question mark. The problem with this approach was users could use unencoded reserved characters in the query string.
err := api.stream.StartStream("?expansions=foo&meta.fields=bar,baz,biz")
In addition, if a user did not want additional data for each tweet, then they would need to use an empty string.
err := api.stream.StartStream("")
After
It is recommended users use a NewStreamQueryParamsBuilder
to build query params. Users should use the values described in twitter's documentation to fetch additional data they need for each tweet.
// Request additional data from teach tweet
streamExpansions := twitterstream.NewStreamQueryParamsBuilder().
AddExpansion("author_id").
AddTweetField("created_at").
Build()
// Start the Stream
err = api.stream.StartStream(streamExpansions)
If no expansions are needed, users can just use nil
for the url values.
err = api.stream.StartStream(nil)
v0.4.0
-
Update examples to showcase an infinite stream
-
Introduce
CreateRulesRequest
to create rules.
rules := twitterstream.NewRuleBuilder().
AddRule("cat has:images", "cat tweets with images").
AddRule("puppy has:images", "puppy tweets with images").
AddRule("lang:en -is:retweet -is:quote (#golangjobs OR #gojobs)", "golang jobs").
Build()
res, err := api.Rules.Create(rules, false) // dryRun is set to false.
- Introduce a
DeleteRulesRequest
to delete rules.
res, err := api.Rules.Delete(rules.NewDeleteRulesRequest(1469776000158363653, 1469776000158363654), false)
v0.3.3
- Update examples to include restarting stream when twitter disconnects
- Promote certain structs to be exported
- Updated how interfaces are used internally
- Corrected some typos
v0.3.2
- Handle 429 status code responses from twitter using exponential backoff #19
v0.3.1
Fixes a race condition where unmarshaling json with bytes.Buffer
across multiple goroutines caused panics.
SetUnmarshalHook
is an optional hook allowing you to unmarshal json in a thread-safe way. By default you will stream []byte
. However, this is not thread-safe.
This hook allows you to unmarshal json in the same goroutine where the bytes.Buffer
was created, making it thread-safe.
See this example for how to use this hook well.
v0.3.0
StartStream
now accepts optional query params.
Example:
api.Stream.StartStream("?expansions=attachments.media_keys,referenced_tweets.id,author_id")
GetMessages
returns a struct which can contain an error from twitter, or it can contain your tweet bytes. It's now up to you to unmarshal the bytes into a struct your create.
go func() {
for message := range api.Stream.GetMessages() {
if message.Err != nil {
panic(message.Err)
}
// Will print something like:
//{"data":{"id":"1356479201000","text":"Look at this cat picture"},"matching_rules":[{"id":12345,"tag":"cat tweets with images"}]}
fmt.Println(string(message.Data))
}
}()
- Updated ReadMe
- Add examples directory
- Add
rulesResponseError
as a possible error returned byrulesResponse
. Learn more here: https://developer.twitter.com/en/support/twitter-api/error-troubleshooting
v0.2.1
StartStream
will return an error if a stream fails to start, nil if successful.- Pass error messages to consumer while streaming. The result is clients must handle possible errors when
GetMessages
is used. SeereadNext
in stream_utils.go for possible list of errors. - Update README
v0.2.0
- Rename package to
twitterstream
RequestBearerToken
now returns (*requestBearerTokenResponse, error)
0.1.0
- Adds unit tests