Lastest Foursquare check-in on map

2019-07-30 01:47发布

问题:

I would like to display a map on my website that shows my last Foursquare check-in.

There is a great blog article explaining how to do this here.

However, I am concerned that I will hit the Foursquare API rate limits (500 requests per hour) since the map will be displayed in the sidebar of the website, so everytime someone views the site (or browses to a different page on the site) it will do a new query to the Foursquare API. As you can see, even with a small amount of traffic it is likely the rate limit will be reached.

Is there a way around this issue, perhaps by either doing some kind of caching or alternatively retrieving my last checkin information through an method other than the Foursquare API? Either way, the check-in needs to be displayed on a Google Map.

I would like to write any scripting in either PHP or Javascript/jQuery.

回答1:

You should definitely not make the API request each time the page is loaded, that could go over the hourly quota quite easily, assuming you have enough visitors to have that be a problem.

Instead, you should have some backend periodically poll for your latest checkin and store it, then have your blog JS request your latest checkin location from your backend.

Even better, you could write your backend to accept real-time updates from the Foursquare API so that it doesn't have to poll at all -- it will get a POST each time you check in, and it can store that information to display it on your blog.