-2
Good morning, you guys! I have the following scenario: I am consuming a Google API that returns me data from a particular Youtube channel, basically I do the request and the return is a list of video Urls. Only the API has a quota of 10,000 requests per day, and this application will receive much more than this daily, because it is a dynamic commercial.
I was wondering if you could determine that only one requisition per day be made. Example: I make a request today, save the values within a variable or object, and the next day make a new request to update the list of Urls.
The code I have is this:
let json = `https://www.googleapis.com/youtube/v3/search?key=${apiKey}&channelId=${userId}&part=snippet,id&order=date&maxResults=${getMax}`;
$.getJSON(json, function(response){
for (var i = 0; i < response['videoId'].length; i++){
var videoId = response['videoId'][i];
let urlVideo = `https://www.youtube.com/embed/${videoId}`;
const newElement = document.createElement('iframe');
newElement.setAttribute('src', urlVideo);
mySiema.append(newElement);
}
});
You cannot store the received data in a database and check whether a request has already been made that day?
– Everton Lenger
Actually I did not want to involve database in this application. It would be possible to do this same check with Javascript?
– Ueslen Santos
Assuming that you will need to store this information somewhere, I can only think of cookies or Torage location. Of course it will not work if the user clears cookies or accesses from a different browser, but maybe it fits your scenario.
– Everton Lenger
Do you want this delivery when the customer comes back to your page or do you want it to be installed in the browser as if it were a deamom? If it is the first case a cookie resolves or web push inviting registered customers to the page. In the second case there is as it is a matter of security and ephemerality of the data in the browser.
– Augusto Vasques
The cookie solution seems to me to be a good one, but how would I ban the request? In this case, how to inform that another request should only be made in 24h?
– Ueslen Santos
I believe it would just save the day you requested the cookie. Before making the request, you check if the last day of the request was today. If it is, you do not make the request.
– Everton Lenger
Thanks friend, really. I will try to solve this problem in this way
– Ueslen Santos
Set a timer to only when given the desired interval, run the request again.
– LeAndrade
I put an answer to make something more visible. If it is useful, you can accept it by clicking on the check that is on the left of the answer. :)
– Everton Lenger