YouTube Android SDK - Invalid Credentials

I am getting error Invalid Credentials

as a result of 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 first get UserRecoverableAuthIOException

as expected. After logging in, 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"
}

      

Added the following to the Google API Console:

  • Client ID for Android Application
  • Client ID for the web application
  • Browser Application Key

I am also using the Google Drive SDK which works great.

In my list of APIs, I am:

  • API driver
  • SDK driver
  • Google+ API
  • YouTube Data API v3
+3


source to share


1 answer


The moment I turned on the bonus, I noticed that the app in question is also associated with a Google employee account. The correct signature for the "Android App Client ID" has been included in this account. Although, I also had the correct signature on the main account under the keys.



Resolved now though.

+2


source







All Articles