Build your own Blockchain Twitter recorder in Go!

­­Where are the real world use cases?

The Twitter use case

Alex Jones believes the world is secretly run by powerful intergalactic child molesters. Seriously.
What? This guy said something racist? Photo credit: MMA Junkie

Setup

Your .env file should look like this
  • go get github.com/gorilla/mux
  • go get github.com/dghubble/oauth1
  • go get github.com/joho/godotenv

Tweet Parsing

  • Tweet allows us to consume results returned by the Twitter API
  • config and token are structs we get back from the oauth1 package we imported. This is a convenience package that easily allows us to make client calls to the Twitter API.
  • pages is set to 18, which is currently the maximum number of pages returned by the Twitter API, which translates to 3000 of a Twitter handle’s latest Tweets
  • maxeMuxRouter creates the handlers we’ll want to pass in a Twitter and handle and get back their Tweets. We’ll be viewing the results in a browser so want to spin up a local server.
  • respondWithError writes a 500 header and returns the error message in the browser if we encounter any failures in our code
  • maxIDQuery is the last Tweet ID of a page of results returned by the Twitter API. We’ll need it to tell Twitter that we want the next page of results, which starts after this ID.
  • tweets is a placeholder slice to consume a list of Tweets
  • the next couple lines of code allow us to parse in the Twitter handle from the URL we’ll use to make a GET request to our program, which will contain the Twitter handle of the user we want
  • http.Client is a new client based on the developer keys we got
  • First, if we hit the last Tweet on the page, we want to skip further processing and tell our program where we left off with maxQueryID
  • We use some regular expressions to filter out @ mentions and links in users’ Tweets. This is optional. If you want to keep them, go ahead.
  • We load our environment variables listed in our .env file into our program with the godotenv package
  • Similarly, we load our config and token variables using the developer keys we got from Twitter
  • We then create and start our server, and we’re done!

Test Run

Hashing

Blockchain

I use Postman to make my REST API requests
Success!

What does this mean?

Data storage

Next steps

Past Tutorials

--

--

Take control of your health. Consolidate records, track medications, set reminders, and monitor health trends with the free #CoralHealthApp.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Coral Health

Take control of your health. Consolidate records, track medications, set reminders, and monitor health trends with the free #CoralHealthApp.