A newbie like to try coding.
Below is the code I copy mostly from a site (found the original post: Facebook Fan Count - Hackster.io). I found that I have to edit few thing to make it work for me.
I also add blinking every refresh to verify it does try to pull a new 'like' number if any.
One thing I am wondering now: there is about 15 seconds delay on the code (my setup) to push the new value from the "facebook-page-like" number.
So does anyone know how to make it able to update every 1 seconds instead 'this 15 seconds'? Much appreciate any response.
I am choosing "NodeMCU 1.0 (ESP12E)" for the board.
You need to select the code and hit the < / > icon in the toolbar for posting your message.
Example:
Your
Code
Will
Then
Look
Like
This
I'm not really clear on the approach you are using..
Have you created some sort of server side script to scrape/collect this data from the page you want results from?
Are you pointing to a reference that returns the count for you or some thing?
IMHO..
1 second might be a pretty tight threshold to maintain.
Its not just the arduino executing its code here.. you are also dealing with HTTP request/responses, passing data, parsing JSON..etc..etc... yadda yadda..
If you are hitting a site itself every 1 second.. your getting close to a DDOS attack! LOL..
It almost seems like overkill....
You could create your own PHP script housed on some server/domain.. call that script. and have it return the 'like count' number by itself.. having the PHP script do most of the work.
Are there other details you are getting?
Can you post an example of what you are querying and what the returned object/data is?
You have a bunch of delays() in there are well.. those are CODE BLOCKING.. meaning nothing else happens until that 'delay' has passed.. then it picks up what it was doing before the delay.
Prophet_Id:
So if 1 seconds is 'too much', how about 2 seconds update/refresh?
I wonder how to improve that 15 secs to "2 secs", if possible.
Looking at your code, if you remove that delay(500) from your JSON section you're hitting the Facebook page as fast as possible - it can't be more than 1 millisecond after receiving the reply that you hit the page again. So how long between hits seems to depend on how long it takes Facebook to respond to you; and how fast you see the like counter update depends on how fast Facebook does this.
If Facebook has a refresh rate of 15 seconds (I really don't know how they actually do this), that's how fast you're going to see your new likes appear.
pert:
You are actually getting likes more frequently than every 15 seconds? Must be quite a page!
Nothing to do with the number actually whether quite or busy page.
More like trying to get a better experience to be able to see the number change right away after you press the 'like button'. Surprisingly able to make they are happy!
xl97:
Without a real URL to test against.. gonna be hard to give you any suggestions then what you already have.
For some reason, Facebook suggests me to keep the exact link hidden, I suppose contained specific 'address'. Although I am not sure what people can do harm if they know that address, maybe meshing up with the page? ha...
But in practice you aren't the one pressing the button. It's some random Facebook user so you have no way of knowing to the second when they pressed the like button. Even if you did, I don't understand why such a minimal delay is a problem.
The only time I could see it mattering is if you had likes coming in every couple of seconds and so the number was jumping up by multiples every 15 second update and a more steady progression was preferred. But we're talking > 8000 likes/day for that to even start being an issue. There are some pages that get that many (celebrities, brands) but the vast majority do not.
wvmarle:
Looking at your code, if you remove that delay(500) from your JSON section you're hitting the Facebook page as fast as possible - it can't be more than 1 millisecond after receiving the reply that you hit the page again. So how long between hits seems to depend on how long it takes Facebook to respond to you; and how fast you see the like counter update depends on how fast Facebook does this.
If Facebook has a refresh rate of 15 seconds (I really don't know how they actually do this), that's how fast you're going to see your new likes appear.
I confirmed that I got a new-like number instantly when you refresh the URL. So it means, this long refresh time is not on the Facebook side. I tested this last night, got a friend pressed the FB page's like-button and I pressed my web browser button and we saw the number up instantly.
pert:
But in practice you aren't the one pressing the button. It's some random Facebook user so you have no way of knowing to the second when they pressed the like button. Even if you did, I don't understand why such a minimal delay is a problem.
The only time I could see it mattering is if you had likes coming in every couple of seconds and so the number was jumping up by multiples every 15 second update and a more steady progression was preferred. But we're talking > 8000 likes/day for that to even start being an issue. There are some pages that get that many (celebrities, brands) but the vast majority do not.
This is the 'application' of this counter I am planning to use:
I have an ice cream store. I place this counter on the place-order counter/cashier with a flashy note "Like our FB page now and you got free one-topping" with a QR Barcode for the URL of my FB page.
The guess saw this note and scan the barcode, press like. In 1 second the counter going up.
The next version I want to add is putting RGB Led and a funny sort sound triggered at the same time when the counter up.
Believe me, seeing the counter moves up after they press the button makes them very happy! (on top of happy for the free stuff).
OK, that makes complete sense! I was thinking of this display as being intended for the page owner, not the page liker. I've seen the former done multiple times by YouTube video channel owners who like to watch their subscriber count grow.
Interesting application indeed.
Add some big flashing lights and loud alarm and you're good to go
You'll have to check with Facebook on whether they have any API that instantly updates, and that you could tap into.
Updating once a second should be enough for this application. No more than twice a second. That's so little delay that most people will barely notice it, it's near-instant.