com.google.android.gms.auth.GoogleAuthException:UNlocated_ON_API_CONSOLE [英] com.google.android.gms.auth.GoogleAuthException: UNREGISTERED_ON_API_CONSOLE

查看:164
本文介绍了com.google.android.gms.auth.GoogleAuthException:UNlocated_ON_API_CONSOLE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实现一个Android应用,该应用使用户可以直接从该应用流式传输到youtube频道.我创建了一个API密钥和一个OAuth 2.0客户端ID

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

但是我得到以下例子:com.google.android.gms.auth.GoogleAuthException: UNREGISTERED_ON_API_CONSOLE当我尝试结束一个事件或尝试获取一个在youtube频道上手动创建的事件时.

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.

我使用以下代码创建youtube对象

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();

然后创建一个事件:

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

推荐答案

问题是,在调试时,您使用的是在〜/.android/debug.keystore中创建的密钥库,而不是您认为的任何签名密钥您正在使用.

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.

生成密钥(例如释放已签名的APK)时,您会认为此SHA1是Google API界面所要求的.不是.

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.

如果您用签名密钥替换〜/.android文件夹中的一个,则它已损坏,因为它缺少androiddebugkey.仅供参考,自动生成的密钥的默认密码是"android".

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".

有关密钥库所在位置的说明,请参见 https://developer .android.com/studio/publish/app-signing.html 在调试证书到期"下.

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".

您必须做什么:

1)删除debug.keystore并重新启动IDE.这应该会生成一个新的debug.keystore,其密钥别名为"androiddebugkey".

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

2)如果您的IDE没有生成新的密钥库,请重新运行您的android应用程序.这次应该在〜/.android/

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

3)导航到/path/to/jre/bin并将此路径添加到系统环境变量中.这将允许您访问keytool.

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

4)导航到调试密钥库的目录并运行以下命令:keytool -list -keystore debug.keystore -alias androiddebugkey

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

5)您的控制台将提示您输入密钥库密码(它是"android").

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

6)从密钥库中获取SHA1密钥,并将THAT KEY放入您的API接口,您会发现它可以正常工作.

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

这篇关于com.google.android.gms.auth.GoogleAuthException:UNlocated_ON_API_CONSOLE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆