You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 5, 2022. It is now read-only.
It is encouraged you set an unmarshal hook for thread-safety. Go's `bytes.Buffer` is not thread safe. Sharing a `bytes.Buffer`
46
-
across multiple goroutines introduces risk of panics when decoding json [source](https://github.com/Fallenstedt/twitter-stream/issues/13).
47
-
To avoid panics, it's encouraged to unmarshal json in the same goroutine where the `bytes.Buffer` exists. Use `SetUnmarshalHook` to set a function that unmarshals json.
49
+
##### Create rules
48
50
49
-
By default, twitterstream's unmarshal hook will return `[]byte` if you want to live dangerously.
51
+
We need to create [twitter streaming rules](https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/integrate/build-a-rule) so we can get tweets that we want.
52
+
The filtered stream endpoints deliver filtered Tweets to you in real-time that match on a set of rules that are applied to the stream. Rules are made up of operators that are used to match on a variety of Tweet attributes.
53
+
Below we create three rules. One for puppy tweets with images, another for cat tweets with images, and the other of unique English golang job postings. Each rule is
AddRule("cat has:images", "cat tweets with images").
60
+
AddRule("puppy has:images", "puppy tweets with images").
61
+
AddRule("lang:en -is:retweet -is:quote (#golangjobs OR #gojobs)", "golang jobs").
62
+
Build()
64
63
64
+
// Create will create twitter rules
65
+
// dryRun is set to false. Set to true to test out your request
66
+
res, err:= api.Rules.Create(rules, false)
65
67
68
+
// Get will get your current rules
69
+
res, err:= api.Rules.Get()
66
70
67
-
##### Start Stream
68
-
Start your stream. This is a long-running HTTP GET request.
69
-
You can get specific data you want by adding [query params](https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/api-reference/get-tweets-search-stream).
70
-
Additionally, [view an example of query params here](https://developer.twitter.com/en/docs/twitter-api/expansions), or in the [examples](https://github.com/fallenstedt/twitter-stream/tree/master/example)
71
+
// Delete will delete your rules by their id
72
+
// dryRun is set to false. Set to true to test out your request
Create a twitterstream instance with your access token from above.
79
+
##### Set your unmarshal hook
80
+
It is encouraged you set an unmarshal hook for thread-safety. Go's `bytes.Buffer` is not thread safe. Sharing a `bytes.Buffer`
81
+
across multiple goroutines introduces risk of panics when decoding json.
82
+
To avoid panics, it's encouraged to unmarshal json in the same goroutine where the `bytes.Buffer` exists. Use `SetUnmarshalHook` to set a function that unmarshals json.
By default, twitterstream's unmarshal hook will return `[]byte` if you want to live dangerously.
116
85
117
-
##### Get Rules
118
-
Use the `Rules` struct to access different Rules endpoints as defined in [Twitter's API Reference](https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/api-reference)
Start your stream. This is a long-running HTTP GET request.
121
+
You can get specific data you want by adding [query params](https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/api-reference/get-tweets-search-stream).
122
+
Additionally, [view an example of query params here](https://developer.twitter.com/en/docs/twitter-api/expansions), or in the [examples](https://github.com/fallenstedt/twitter-stream/tree/master/example)
133
123
134
-
##### Add Rules
135
-
```go
136
-
res, err:= api.Rules.AddRules(`{
137
-
"add": [
138
-
{"value": "cat has:images", "tag": "cat tweets with images"}
0 commit comments