Cyborg771
Cyborg771

Reputation: 405

YouTube Data API says I've exceeded by daily usage limits when left idle for a few hours

I'm working on a web app that displays a list of youtube videos for the user to watch, and it's working fine, but when I leave the app alone for a period of time, 45 minutes or so, when I try to make another API request I get a 403 Error: "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup." If I refresh the page it works fine again and it doesn't matter how many individual requests I've made, it simply seems to be a timeout. I can't find any specifics on how long this timeout is, how to prevent or extend it, or anything else. Does anyone know?

Also, if I manually call the gapi.client.setApiKey() and gapi.client.load() again from the javascript console it works just fine, I figure I can just set a 30 minute timeout or whatever to refresh this but that seems kind of annoying.

Upvotes: 0

Views: 1216

Answers (1)

Rob M.
Rob M.

Reputation: 36541

Your oauth access token is timing out. The accessToken only lasts 60 minutes, so when you don't refresh the page (and get a new accessToken presumably), you are attempting to use an expired accessToken which results in that error message. You could look into using refresh tokens, which allows you to request a new accessToken once yours has expired. This page explains how to setup refresh tokens

Upvotes: 1

Related Questions