Skip to content
This repository has been archived by the owner on Nov 5, 2022. It is now read-only.

Commit

Permalink
add comments to examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Fallenstedt committed Dec 22, 2021
1 parent 4006516 commit 61f7cf0
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions example/stream_forever.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,29 +75,37 @@ func initiateStream() {
}

func fetchTweets() stream.IStream {
// Get Bearer Token using API keys
tok, err := getTwitterToken()
if err != nil {
panic(err)
}

// Instantiate an instance of twitter stream using the bearer token
api := getTwitterStreamApi(tok)

// On Each tweet, decode the bytes into a StreamDataExample struct
api.SetUnmarshalHook(func(bytes []byte) (interface{}, error) {
data := StreamDataExample{}
if err := json.Unmarshal(bytes, &data); err != nil {
fmt.Printf("failed to unmarshal bytes: %v", err)
}
return data, err
})

// Request additional data from teach tweet
streamExpansions := twitterstream.NewStreamQueryParamsBuilder().
AddExpansion("author_id").
AddTweetField("created_at").
Build()

// Start the Stream
err = api.StartStream(streamExpansions)
if err != nil {
panic(err)
}

// Return the twitter stream api instance
return api
}

Expand Down

0 comments on commit 61f7cf0

Please sign in to comment.