Search code examples
phpoauthyoutube-apiauthsubgoogle-authentication

Permanent access token with YouTube api?


I have gone through the google documentations for Oauth and AuthSub methods for authenticating and I've tried to google this without results.

For Facebook, you can request an access token which is of length lifetime, meaning you won't have to be requesting a new token every few weeks. What about Google, and YouTube in specific, is there any authentication method which allows you to use that token permanently?

In their documentation they state that they have long-life but no sort of additional detail, of exactly how long and whether or not you could actually get one which never expires.

Specifically, I am making an application that needs to login on a few accounts daily, but it is run through cron so there isn't gonna be a user logging it in each time, and I'd prefer not store the actual user/pass to the application itself and use the tokens instead.


Solution

  • Finally found it. They don't expire. You have to make sure to perform the last step, exchanging your single use token for a session token. That session token should not expire.

    Here's what my step (using the Google AuthSub Client Library) looks like in C#:

    sessionToken = AuthSubUtil.exchangeForSessionToken(authToken, null);
    

    Simple enough. I'm sure it's probably something very similar for the PHP library. Just store that sessionToken instead of the authToken

    Check out the AuthSub process flow. Specifically the very last step (#7)