gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 19:00:01 25 4
gpt4 key购买 nike

我正在实现一个 Android 应用程序,使用户能够直接从该应用程序流式传输到 YouTube channel 。我已经创建了一个 API key 和一个 OAuth 2.0 客户端 ID enter image description here

但我得到以下异常:com.google.android.gms.auth.GoogleAuthException: UNREGISTERED_ON_API_CONSOLE 当我尝试创建事件或尝试获取手动创建的事件时在 youtube channel 上。

我使用以下代码创建一个 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 中创建的 keystore ,而不是您认为正在使用的任何签名 key 。

当您生成一个 key 时,例如发布一个签名的 APK,您认为这个 SHA1 是 Google API 接口(interface)所需要的。它不是。

如果您将 ~/.android 文件夹中的 key 替换为您的签名 key ,则它已损坏,因为它缺少 androiddebugkey。仅供引用,自动生成 key 的默认密码是“android”。

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

你必须做的:

1) 删除您的 debug.keystore 并重新启动您的 IDE。这应该会生成一个新的 debug.keystore, key 别名为“androiddebugkey”。

2) 如果您的 IDE 没有生成新的 keystore ,请重新运行您的 android 应用程序。这次它应该在 ~/.android/中生成它

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

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

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

6) 从 keystore 中获取 SHA1 key 并将该 key 放入您的 API 接口(interface)中,您会发现它可以工作。

关于android - com.google.android.gms.auth.GoogleAuthException : UNREGISTERED_ON_API_CONSOLE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40941556/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com