Introduction: Raspberry Pi Instagram Followers Counter
How does the Instagram Counter work?
When Raspbian OS boots up, the Node.js server starts automatically, listening on the local address of the Raspberry Pi(localhost 127.0.0.1). Right after, Chromium opens up in kiosk mode (full screen) loading the web page served by the Node.js server. The user is first presented with an Instagram login screen. The user enters the account credentials from which the data should be retrieved. After login, the counter starts.
Next you will see how to enable an Instagram developer account and download the Instagram counter to your Raspberry Pi.
Step 1: Enabling Your Instagram Developer Account
To develop applications using Instagram API, it is necessary to enable your personal Instagram account so that your account can be used as a developer account.
Go to the following link: https://www.instagram.com/developer/, click on Enter (top right corner) and type your Instagram account credentials.
After login, click on Register Your Application.
You will then be presented with a form. Fill in the necessary information. Can be the same as the picture above. The most important are the Valid Redirect URI's. The URI's must be the same as in the picture. After you fill in the form, click on Register.
Your new Instagram client application is now created. Click on Manage to see the two credentials needed for the Node.js application. You will put the credentials inside the source code later.
Step 2: Installing the Node.js Instagram Counter Application
Be sure that your Raspberry Pi has Node.js version 6 or later installed. Execute node --version to check. The best way to install and manage Node.js versions is using NVM (Node Version Manager). More info on NVM you find here.
Clone the GitHub repository where all the source code and dependencies of the instagram counter is located. You should clone inside /home/pi/ folder.
git clone https://github.com/giobauermeister/ig-followers-counter-raspberrypi.git
Enter in the new cloned repository:
Install local dependencies of the application.
Install the package forever as global dependency of the application. Forever will be used to launch the Instagram counter application.
npm install forever -g
With a text editor, open up app.js and fill in the credentials showed earlier from Instagram Developer website.
client_id: 'xxxxxxx', client_secret: 'xxxxxxx' });
Step 3: Manually Launching the Application
Before launching the application, be sure that your Raspberry Pi has internet connection.
To launch the application run the command node app.js. If everything went right, you should see the message on console: “Server listening on 127.0.0.1:8080…”.
Server listening on 127.0.0.1:8080...
Open up another command terminal and run the following command to open Chromium in kiosk mode accessing the server address.
chromium-browser --incognito --window-size=800,480 --kiosk "http://localhost:8080/authorize_user"
After running the command above, Chromium should open, prompting the user with an Instagram login screen. Type in the credentials of the Instagram account you want to retrieve data.
An authorization screen should open saying that our client application created before wants to access some basic information of media and profile. Click on Authorize.
Finally you will see the counter and after a few seconds it should start counting you Instagram followers. Ask a friend to follow you to see it in action!
Step 4: Configuring Auto Launch With Systemd
Now that the server is running correctly, let's configure the Raspberry pi so our counter starts automatically after boot. To do so we will make use of Systemd.
Copy the file "launch-ig-counter.service" to the folder /lib/systemd/system/.
sudo cp launch-ig-counter.service /lib/systemd/system/
Enable the service in the system.
sudo systemctl enable launch-ig-counter.service
Start the service.
sudo systemctl start launch-ig-counter.service
Verify that the service is running correctly with the command bellow:
sudo systemctl status launch-ig-counter.service
You should see active (running).
launch-ig-counter.service - Start Instagram Followers Counter
Loaded: loaded (/lib/systemd/system/launch-ig-counter.service; enabled) Active: active (running) since Wed 2017-06-14 10:01:26 BRT; 8s ago Main PID: 7233 (launch-ig-count)
With that, the application will always start after Raspbian boots up.
Step 5: Conclusion
Now it is easy to stay up to date with you Instagram account popularity in real time!
In this tutorial you learned how to create an application in Node.js that uses Instagram API to retrieve the number of followers of a given account.
See above the Instagram Followers Counter in action!
If you explore Instagram API you can see that it is possible to retrieve other types of data such as number of likes on a photo, profile pictures, usernames, photos tagged by a #, etc, etc...
Feel free to explore also the other files available in this project such as app.js, index.html, launch-ig-counter.service, launch-ig-counter.sh, etc...
Any questions and feedback, feel free to leave a comment down bellow!
This project was first published in Portuguese on FILIPEFLOP's Blog. FILIPEFLOP is an electronics components and hardware online store located in Brazil.
Participated in the
First Time Author Contest