15

Im implementing an android app that enables users to stream to a youtube channel straight from the app. I have created an API key and a OAuth 2.0 client ID enter image description here

But I get a the following exeption: com.google.android.gms.auth.GoogleAuthException: UNREGISTERED_ON_API_CONSOLE either when I try to ceate an event or when i try to fetch the one a created manually on the youtube channel.

I use the following code for create a youtube object

String accountName = mContext.getString(R.string.google_account_name);
        String apiKey = mContext.getString(R.string.google_api_key);
        String clientID = mContext.getString(R.string.google_api_client_id);
        String clientName = mContext.getString(R.string.google_api_client_name);

        GoogleAccountCredential credential =
                GoogleAccountCredential.usingOAuth2(mContext,
                        Arrays.asList(YouTubeScopes.YOUTUBE));
        credential.setSelectedAccountName(accountName);

//        String SCOPE = "audience:server:client_id:" + clientID + ":api_scope:" + YouTubeScopes.YOUTUBE;
//        GoogleAccountCredential credential = GoogleAccountCredential.usingAudience(mContext, SCOPE);
//        credential.setSelectedAccountName(accountName);


        youtube = new YouTube.Builder(transport, jsonFactory, credential)
                .setApplicationName(clientName)
                .setYouTubeRequestInitializer(new YouTubeRequestInitializer(apiKey))
                /*.setGoogleClientRequestInitializer(new YouTubeRequestInitializer(apiKey))*/
                .build();

Then to create an event:

LiveBroadcastSnippet broadcastSnippet = new LiveBroadcastSnippet();
broadcastSnippet.setTitle(name);
broadcastSnippet.setScheduledStartTime(new DateTime(futureDate));

LiveBroadcastContentDetails contentDetails = new LiveBroadcastContentDetails();
MonitorStreamInfo monitorStream = new MonitorStreamInfo();
monitorStream.setEnableMonitorStream(false);
contentDetails.setMonitorStream(monitorStream);

// Create LiveBroadcastStatus with privacy status.
LiveBroadcastStatus status = new LiveBroadcastStatus();
status.setPrivacyStatus("unlisted");

LiveBroadcast broadcast = new LiveBroadcast();
broadcast.setKind("youtube#liveBroadcast");
broadcast.setSnippet(broadcastSnippet);
broadcast.setStatus(status);
broadcast.setContentDetails(contentDetails);

// Create the insert request
YouTube.LiveBroadcasts.Insert liveBroadcastInsert = youtube
        .liveBroadcasts().insert("snippet,status,contentDetails",
                            broadcast);
    
// Request is executed and inserted broadcast is returned
LiveBroadcast returnedBroadcast = liveBroadcastInsert.execute(); //<= This line generates the exception

I obviously did something wrong, but I can't figure out what. Any help is appreciated. Thanks in advance

4 Answers 4

16

The issue is that, when you debug, you're using a keystore created in ~/.android/debug.keystore, and not whatever signing key you think you're using.

When you generate a key, such as to release a signed APK, you think that this SHA1 is the one required by the Google API interface. It isn't.

If you replace the one in the ~/.android folder with your signing key, it's corrupt because it's missing the androiddebugkey. FYI, the default password for the auto-generated key is "android".

For directions as to where your keystore is located, see https://developer.android.com/studio/publish/app-signing.html under "Expiry of the debug certificate".

What you have to do:

1) Delete your debug.keystore and restart your IDE. This should generate a new debug.keystore with key alias "androiddebugkey".

2) If your IDE does not generate the new keystore, re-run your android application. It should generate it this time in ~/.android/

3) Navigate to /path/to/jre/bin and add this path to your system environment variables. This will allow you to access keytool.

4) Navigate to the directory of your debug keystore and run this command: keytool -list -keystore debug.keystore -alias androiddebugkey

5) Your console will prompt you to enter the keystore password (it is "android").

6) Get the SHA1 key from the keystore and put THAT KEY into your API interface, and you'll find it works.

3
6

In my case the UNREGISTERED_ON_API_CONSOLE error was caused by misspell in package name in AndroidManifest. Simple but lost many hours struggling with keys and SHAs.

1
  • Or when you switch from debug key to a final one and forget to update your SHA. Gosh! Wasted hours of my life.
    – Alberto
    Jan 7, 2017 at 21:29
2

Using the answers before this, I used it as a reference to understand and fix mine and made a much easier step-by step procedure of how I fixed mine.

In Windows command prompt.

Navigate to you java bin directory.

C:\Program Files\Java\jdk1.8.0_111\bin>

and type the ff. command

keytool -list -v -keystore "%USERPROFILE%\.android\debug.keystore" -alias androiddebugkey -storepass android -keypass android

then run the ff. code

keytool -list -keystore  "%USERPROFILE%\.android\debug.keystore" -alias androiddebugkey

when ask for password, type "android" (without double quotes)

the resulting SHA1 key from the above code. Copy it, and paste it on your google cloud console here

enter image description here

On the google cloud console webpage do this

on the tab on the left, find and click "APIs & Services"

then on the new page, on the left tab again, find and click "Credentials"

now copy paste the key you copied from windows command prompt on the textbox below the "Signing-certificate fingerprint"

make sure that the application id on your app and google cloud console matches each other.

enter image description here

0

I've this problem, and after a lot of search, in build.gadle my applicationId was diferent from the package name that i've putted on Google Console

defaultConfig {
    applicationId "br.com.glicado.glicado" <-- WAS WRONG, IN MY CASE THE RIGHT IS "br.com.glicado"
    minSdkVersion 15
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.