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