I am receiving the Invalid Credentials
error as a result to the following unit test:
List<String> scopes = new ArrayList<String>();
scopes.add(YouTubeScopes.YOUTUBE_READONLY);
try {
GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(this, scopes);
credential.setSelectedAccountName(account.name);
YouTube.Builder builder = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential).setApplicationName("TestApp");
YouTube youtube = builder.build();
YouTube.Channels.List channelRequest = youtube.channels().list("contentDetails");
channelRequest.setMine(true);
ChannelListResponse channelResult = channelRequest.execute();
List<Channel> channelsList = channelResult.getItems();
for(Channel channel : channelsList) {
// Do things
}
} catch (UserRecoverableAuthIOException e) {
e.printStackTrace();
startActivityForResult(e.getIntent(), RESULT_REQUEST_AUTH);
} catch (IOException e) {
e.printStackTrace();
}
When using this code, I firstly get the UserRecoverableAuthIOException
, as expected. Once authorization has been given, I get the following error:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized
{
"code" : 401,
"errors" : [ {
"domain" : "global",
"location" : "Authorization",
"locationType" : "header",
"message" : "Invalid Credentials",
"reason" : "authError"
} ],
"message" : "Invalid Credentials"
}
I have the following added to my Google API Console:
- Client ID for Android application
- Client ID for web application
- Key for browser applications
I also use the Google Drive SDK, which functions perfectly.
Under my list of APIs, I have:
- Drive API
- Drive SDK
- Google+ API
- YouTube Data API v3