其他分享
首页 > 其他分享> > com.google.android.gms.auth.GoogleAuthException:UNREGISTERED_ON_API_CONSOLE

com.google.android.gms.auth.GoogleAuthException:UNREGISTERED_ON_API_CONSOLE

作者:互联网

我实现了一个Android应用程序,使用户可以直接从应用程序流式传输到YouTube频道.我创建了一个API密钥和一个OAuth 2.0客户端ID enter image description here

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

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

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

我显然做错了什么,但我无法弄清楚是什么.任何帮助表示赞赏.提前致谢

解决方法:

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

当您生成密钥(例如发布已签名的APK)时,您认为此SHA1是Google API界面所需的密钥.事实并非如此.

如果用你的签名密钥替换〜/ .android文件夹中的那个,它就会损坏,因为它缺少androiddebugkey.仅供参考,自动生成密钥的默认密码是“android”.

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

你要做什么:

1)删除debug.keystore并重新启动IDE.这应生成一个带有键别名“androiddebugkey”的新debug.keystore.

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

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

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

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

6)从密钥库中获取SHA1密钥并将THAT KEY放入API接口,你会发现它有效.

标签:android,android-youtube-api
来源: https://codeday.me/bug/20190928/1828814.html