I am need to upload video to youtube to specific youtube account. So I need to authenticate I am using java google lib. Code looks like this:
          Credential credential = new GoogleCredential.Builder()
            .setTransport(new ApacheHttpTransport())
            .setJsonFactory(new JacksonFactory())
            .setServiceAccountId("xxx@xx-app.iam.gserviceaccount.com")
            .setClientSecrets("xx@gmail.com", "xx")
            .setServiceAccountPrivateKeyFromP12File(new File("xx.p12"))
            .setServiceAccountScopes(scopes)
            .setServiceAccountUser("xx@gmail.com")
            .build();
          youtube = new YouTube.Builder(credential.getTransport(), credential.getJsonFactory(), credential).setApplicationName(
            "tellews-app").build();
          Video returnedVideo = videoInsert.execute();
          YouTube.Videos.Insert videoInsert = youtube.videos()
            .insert("snippet,statistics,status", videoObjectDefiningMetadata, mediaContent);
          Video returnedVideo = videoInsert.execute();
And getting error:
IOException: 401 Unauthorized
{
  "error" : "unauthorized_client",
  "error_description" : "Client is unauthorized to retrieve access tokens using this method."
}
Maybe someone sees what I am doing wrong
 
     
    