This project is hosted on Glitch: https://glitch.com/~dailynasa
Once a day, NASA features an astronomy or space science related image through their public API. The images are pretty cool and teach you about the incredible solar system we live in!
As an astronomy enthusiast, I wondered how I could easily view these images and even get them to appear on my Twitter timeline. I got to work on this, and ended up putting together this fully automated Daily NASA app that Tweets images released each day by NASA.
Our node.js app will connect to the NASA API, temporarily store media provided and post a Tweet with the title + image/video via the Twitter API. Here is an example. Pretty simple!
In this tutorial, I'll also show you how to build this app using the Twitter and NASA APIs. To see the app in action, check out the Twitter page @DailyNASA.
Our app is going to be hosted on Glitch, so we won't be doing much except making sure our app is properly configured.
Once our project has been remixed and the
.env file's keys and tokens properly configured, we'll schedule a cron-job to make our app Tweet. A cron-job is essentially an automated wake-up call.
- The app will be activated via a webhook. The webhook will be pinged by our cron-job at a specified time of day ⏰
- Our app will connect to the NASA API 🚀
- The app will check if the media provided by the NASA API is an image URL or video URL. If it’s a photo, our app will download the image and Tweet it. If it’s a video, the app will just Tweet the video URL:
- Video 📹 - the app will save the video URL + title and Tweet this via the Twitter statuses/update endpoint. Here’s an example.
- Image 📷 - the app will save the image to a temporary directory and Tweet this via the Twitter statuses/update endpoint. Here’s an example. Because it's a temporary directory, we don't have to worry about filling up space (pun intended) 🥁
Before we get started, you'll need the following:
A Twitter developer account - click here to apply
A NASA API key 🔑 - click here to get one
A cron-job account - click here to register
Once you have all of these, you're ready to launch 🚀!
Step 1 - 💿
a) On our Glitch project page, remix this project! Click on the "Remix Project" button on the top left of this page.
b) Name your app.
I called mine
Step 2 - 🔑
A) Enter your Twitter apps keys and tokens in the projects
B) Enter your NASA API Key on the projects
C) Give your app endpoint a name
For example, if I label mine
.env file should look like this:
BOT_ENDPOINT='awaken'. My final endpoint will look like this:
🚨 IMPORTANT - keep all access keys, tokens, and endpoint names private 🚨
Step 3 - TESTING TESTING !!
Now you've configured our app, let's test it out.
I usually reccomend viewing the logs in Tools → Logs to verify our app runs when we wake it up.
In a new browser window, enter your unique endpoint URL and hit enter. (You can also test the URL via your command line using the following command:
Give it a second, and on your Twitter account you should see the daily NASA Tweet posted!
Now you've verified that it works, let's make sure that it's automated so you don't have to keep doing this every single day.
Step 4 - ⏰
We'll be using cron-job.org to ping our endpoint and make our app post a daily Tweet.
Create a new cron-job and fill out the page to this effect:
🚨 IMPORTANT - scheduling your app to run too frequently can seem spammy and lead to violation of Twitters automation policy. 🚨
Once a job has run, you can view the response on this page.
And just like that, we're done!
You did it! 😎
If you enjoy learning from tutorials or have any questions, check out Twitter’s Community Forums.