I've a requirement to run a background service to pull Youtube Analytics for already linked channel on a daily basis using Youtube Analytics API
Since it'll be in the background, having a direct accesses with Google's Oauth services would be good like with grant_type client_credentials. But, the flow covered in all the samples Provided here, needs an entire flow where user has to Authorize from browser using Authorisation Flow
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, scopes).setCredentialDataStore(datastore)
.build();
// Build the local server and bind it to port 8080
LocalServerReceiver localReceiver = new LocalServerReceiver.Builder().setPort(8080).build();
// Authorize.
return new AuthorizationCodeInstalledApp(flow, localReceiver).authorize("user");
I've also tried working with an API key, but that is not supported by Analytics API. Anybody knows any way to generate and retrieve access_token based on a service account which allows backend job to consume Analytics API?
There are three main types of credetilas that can be created on Google developer console.
The Credentials file for each of those types is different as is the code. THe code you are using is for an installed application hence the
AuthorizationCodeInstalledAppso unless you created installed credentials that code isn't going to work.The code for service accounts should be something like this.