1

Currently I`m working on a multi client youtube service that receives my playlists. I used the FileDataStoreFactory to store necessary credentials for every client. My problem is that I can only successfully access the youtube api for the first hour after the manual authorization. When my access token expires I cant refresh my token for accounts with multiple channels or other youtube accounts attached. It all works fine when I try it with a stored credential of a client that has only its main youtube account (nothing else attached). So it works only for certain clients..

Every time I try to refresh token I get a "401 Unauthorized" with no other details about what caused the exception to be thrown..

"com.google.api.client.auth.oauth2.TokenResponseException: 401 Unauthorized"

This is how I authorize:

GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
          HTTP_TRANSPORT, JSON_FACTORY,
          client.getoAuthClientID(),
          client.getoAuthClientSecret(), scopes)
            .setDataStoreFactory(getDataStoreFactory(client))
            .build();

return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");

I initially set up my dev console project as intalled application, so I have the right credentials..

lastly I get the youtube instance like this:

youTube = new YouTube.Builder(googleOAuthService.getHttpTransport(), googleOAuthService.getJsonFactory(), cred)
          .setHttpRequestInitializer(cred)
          .setApplicationName(applicationName)
          .build();

The youtube account has 3 channels.. I set one as the main channel that is linked with the gmail address. <- this is how it doesnt work

I have another account with only the default channel for the gmail address and somehow it works for this kind of account without configuring anything.

Did someone experience the same or knows what I`m doing wrong?

thanks in advance

heiningair
  • 441
  • 1
  • 6
  • 23
  • Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example. – Linda Lawton - DaImTo Jul 01 '15 at 10:00
  • Thats the problem.. The code works just fine for most clients. Only the ones that have multiple accounts attached are concerned. I guess it is just about configuration.. maybe it is a known problem. – heiningair Jul 01 '15 at 11:51
  • Do you use incremental authorization as described here: https://developers.google.com/identity/protocols/OAuth2WebServer#incrementalAuth – Kay_N Jul 09 '15 at 01:46

0 Answers0