I am getting this error, "(#613) Calls to graph_url_engagement_count have exceeded the rate of 10 calls per 3600 seconds." so I want to keep the calls to the API within the limit for a given link.
Note: That the limit of 10 calls per hour only applies to each link.
This is the function I am using:
const getFacebookStats = async (link) => {
try {
const resp = await axios.get(
`https://graph.facebook.com/v12.0/?id=${link}&fields=engagement&access_token=${BEARER_TOKEN_FACEBOOK}`
);
return resp.data.engagement;
} catch (err) {
// Handle Error Here
console.error(err);
}
};
Any help would be much appreciated.
Thank you
Solved this problem using LRU cache.
cache.set(link, cache.get(link) == undefined ? 1 : cache.get(link) + 1);
Everytime the link was passed onto the getFacebookStats function, the link and its count were stored in the LRU cache, if the same link was being called multiple times then its count got incremented.
In the settings of LRU cache, maxAge was set to 1 hour:
maxAge: 1000 * 60 * 60,