Facebook Fan Count




Introduction: Facebook Fan Count

Inspired by Becky Stern's YouTube Subscriber Counter, I wanted to make a display of the number of likes for a Facebook page. My goal with this project was to bring out the number of fans from a Facebook page. Not any one but one I administer. To code C is not my field so I started with a lot of trial and error. But ended up with a result that worked.

This is what you need for this project:


Facebook APP https://developers.facebook.com/

Facebook fingerprint https://github.com/gbrault/esp8266-Arduino/blob/master/doc/esp8266wifi/client-secure-examples.md#how-to-verify-servers-identity

Arduino IDE https://www.arduino.cc/en/Main/Software

Libaries for Arduino IDE

    WIFI ESP8266 https://github.com/esp8266/Arduino

    Seven segment display https://github.com/bremme/arduino-tm1637

    JSON https://github.com/bblanchon/ArduinoJson


    Ikea Ribba 000.783.34 (or another frame to hold the project) http://www.ikea.com/no/no/catalog/products/0007833...

    NodeMCU (mini) https://www.banggood.com/Mini-NodeMCU-ESP8266-WIFI...

    Display https://www.banggood.com/RobotDyn-LED-Display-Tube...


    Rotary tool or something to make a square hole in the backplate of the frame.

    Step 1: Create Facebook APP

    This can be done at developers.facebook.com. After the APP is created, note the App ID and App Secret. You'll need this in the code.

    Wanna test the access for your APP? Head over to https://developers.facebook.com/tools/explorer/

    Enter the following: AAA?access_token=BBB|CCC&fields=fan_count

    • AAA = Facebook Page ID or name,
    • BBB = App ID
    • CCC = App Secret

    Note the | (pipe) between App ID and App Secret.

    Step 2: Hardware – Electronics

    Now over to the fun part. I have used a NodeMCU Mini. These are available in various varieties and price ranges in a variety of online stores and on eBay. There were two reasons I chose a mini. The first reason was that I already had a lying one in my drawer. The other reason was that it is small and takes up little space in a picture frame.

    I bought a display consisting of four segments mounted on a board of electronics so I only need to use four of NoceMCUen's IOs.

    NOTE: NodeMCU has only 3.3V output while the display will preferably have 5V. It will work with 3.3V but will light slightly. Fortunately for me my NodeMCU gives 5V outputs via VIN.

    As you can see on my somewhat blurry image the VIN, VCC and data pin are aligned. This means I don't need any wires between the NodeMCU and display. Just slide the boards together and add some soldering.

    • VIN --> 5V
    • GND --> GND
    • D4 --> DIO
    • D3 --> CLK

    Disclaimer: I do not take responsibility for connecting your equipment together and any damage that may occur on your equipment if you follow my example. Fortunately, this setup seems to work me.

    Step 3: Hardware – Frame

    I bought a Ikea Ribba 000.783.34. The reason why I bought this frame is that it has a deep frame. Then I can easily fit the display and the electronics.

    The picture above shows that I have made holes for the display. I made a template that I attached to the backplate and marked where I wanted to have the display. Then I used a rotary tool to make the hole.

    The next step was to tweak the placement of the display and make it as bright as possible through the paper in front. As you probably understand, I did not start with the frame itself. For it would be useless to build a display in a frame if I did not have a number to display.

    After I had created a Facebook APP, I had to put myself into a somewhat unknown world. I do not know much about programming C ++. But ended up with a satisfactory result after much trial and error.

    Step 4: Software – Arduino Libaries

    WIFI: In order to connect to wireless networks, we need a library for ESP8266. If you do not have this before, go here https://github.com/esp8266/Arduino and follow the steps for adding it to Arduino IDE.

    Display: The next library is for the seven segment display. Download the SevenSegmentTM1637 Arduino Library from https://github.com/bremme/arduino-tm1637 I tried several different libraries for the display. This one was the first I found that worked with my display board.

    JSON: The last library is for handling JSON-data from Facebook. Download ArduinoJson - C++ JSON library for IoT from https://github.com/bblanchon/ArduinoJson

    Facebook Fingerprint: To connect to Facebook we also needs a fingerprint. Instead of trying to explain this to you, I recommend taking a look at the documentation https://github.com/gbrault/esp8266-Arduino/blob/ma...

    Step 5: Software – Code

    Download the code here: https://www.hackster.io/code_files/114510/download

    • AAA = Facebook Page ID or name
    • BBB = Facebook App ID
    • CCC = App Secret
    • DDD = Fingerprint



      • Tiny Home Contest

        Tiny Home Contest
      • Water Contest

        Water Contest
      • Creative Misuse Contest

        Creative Misuse Contest

      18 Discussions

      Hi All, here the code that work for me, very small changes I figured for sleeping late in the last 2 days (I have no skill in coding at all, so just trial here and there comparing the code I got from the examples). I add blinking every refresh to verify it does pulling new number if any.

      One question though I love to get answered. There is about 15 seconds delay on the code (my setup) to push the new value from the facebook like number. How to make it updated every 1 seconds instead 'this 15 seconds'?

      I am choosing "NodeMCU 1.0 (ESP12E)" for the board.


      #include <ESP8266WiFi.h>

      #include <WiFiClientSecure.h>

      #include "SevenSegmentTM1637.h"

      #include <ArduinoJson.h>

      #define LED_BUILTIN 2

      // Wifi

      const char* ssid = "JohnDoe";

      const char* password = "JD1234567890";

      // Facebook

      // https://github.com/gbrault/esp8266-Arduino/blob/m...

      const char* host = "graph.facebook.com";

      const String url = "/johndoe?access_token=xxxxxxxxxxxxxxx|yyyyyyyyyyyyyyyyyyy&fields=fan_count";

      const int httpsPort = 443;

      const char* fingerprint = "xxxxxxxxxxxxxyyyyyyyyyyyyyyyzzzzzzzzzzzzzz";

      // Display https://github.com/bremme/arduino-tm1637

      const byte PIN_CLK = D3; // define CLK pin (any digital pin)

      const byte PIN_DIO = D4; // define DIO pin (any digital pin)

      String payload;

      SevenSegmentTM1637 display(PIN_CLK, PIN_DIO);

      void setup() {



      // Wifi



      Serial.print("Connecting to ");


      WiFi.begin(ssid, password);

      while (WiFi.status() != WL_CONNECTED) {





      Serial.println("WiFi connected");

      Serial.print("IP address: ");


      Serial.print("Netmask: ");


      Serial.print("Gateway: ");


      // Display

      display.begin(); // initializes the display

      display.setBacklight(100); // set the brightness to 100 %




















      void loop() {

      String wifistatus = "WIFI OK";

      // Use WiFiClientSecure class to create TLS connection

      WiFiClientSecure client;

      const int httpPort = 80;

      if (!client.connect(host, httpsPort)) {

      String wifistatus = "WIFI FAIL";

      Serial.println("connection failed");



      client.print(String("GET ") + url + " HTTP/1.1\r\n" +

      "Host: " + host + "\r\n" +

      "User-Agent: BuildFailureDetectorESP8266\r\n" +

      "Connection: close\r\n\r\n");

      Serial.println("request sent");

      while (client.connected()) {

      String line = client.readStringUntil('\n');

      if (line == "\r") {

      Serial.println("headers received");




      // JSON

      String line = client.readStringUntil('\n');

      DynamicJsonBuffer jsonBuffer;

      JsonObject& root = jsonBuffer.parseObject(line);

      int fancount = root[String("fan_count")];

      if (fancount > 0) {

      Serial.print("Fans: ");






      } else {






      2 replies

      Reply 7 months ago

      Or did I missunderstand your quiestion? The 15 seconds from startup to the first number displays. It takes some time for the board to connect to wifi and then to Facebook.

      I keep having certificate does not match yet my headers are receives and my serial monitor won;t indicate the fan_count at all, pls help me :(

      I keep having certificate does not match and my serial monitor wont indicate the fan_count at all, pls help me :(

      Would love to get this working but am having issue where i compile and get this...

      exit status 1

      'd3' was not declared in this scope

      I have changed D3 and D4 to simply 3 and 4 to check if that might be it and that compiles and uploads fine but i dont think that correct. but no matter what i do it just tells me the pin was not declared in the code.

      Also, does it matter what board you select in the Ardiuno program... (tools -> board). Should it be generic ESP8266 Module or maybe NodeMCU 0.9 or the 1.0?

      Would really like to get this running!

      4 replies

      Depending on what type of board you have you should select the board that fits in Arduion IDE. There are several types and you might have to download a libary for your type of board.

      Depending what works for your board you can define the pins in different way. Try some of the examples from the display libary to check if it works: https://github.com/bremme/arduino-tm1637/tree/master/examples

      I have the exact same boards and display as you have listed. I did get this running, but gives ERR1 now everytime it connects. Im guessing my access token needs to be renewed every hour? Is there a way of getting an access token that has no expiry?

      To be honest, I have never received the ERR1 message myself. The reason for ERR1 is that fancount is not greater than 0. That is, it is 0 or less. It may also be that fancount is not a number. A little bad code, because this should have been checked in advance.

      Try a Serial.println(fancount); Between lines 69 and 70. Is there a number or something else?

      I have never renewed my access token. My display has run without errors since May. There may be a problem with your Facebook APP or settings.

      Seem to be getting "certificate doesn't match" on every try.


      obtain the fingerprint for specific host using a web browser. For instance on Chrome press Ctrl+Shift+I and go to Security > View Certificate > Details > Thumbprint. This will show a window like below where you can copy the fingerprint and paste it into sketch.

      Can you explaing more detalied about Hardware – Electronics?

      Can you tell us exact part that you use for this project?

      Thanks! Great project!

      3 replies

      Hi FlavuiB2, I have updated the instruction with more details about the hardware. As you can see I use a NodeMCU Mini and a display (both bought at Banggoods, but you can get similar products elsewhere).

      As you can see from the photo (it a little blurry) the IOs align. So I just slide the NodeMCU into the existing pins on the display board. Then added some soldier to make sure it stayed like this.

      Just ask if there is something else you wanna know.


      It looks similar and it will probably work. What you have to check is the VCC and if it's capable to drive the display directly from the NodeMCU-board. Otherwise you have to power the display in another way.

      That looks good, it would be fun to have a tracker like that :)