- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在实现一个 Android 应用程序,使用户能够直接从该应用程序流式传输到 YouTube channel 。我已经创建了一个 API key 和一个 OAuth 2.0 客户端 ID
但我得到以下异常: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/
我正在使用 GoogleUtilAuth.getToken() 生成 token 。我还生成了两个客户端 ID,一个用于网页,一个用于 Android 应用程序,两者都在同一个项目中。点击此链接 ve
我有 android、google 授权问题(类似于 .GoogleAuthException: Unknown while doing Google SSO. - 没有答案): 09-29 00:0
异常(exception): 07-28 14:36:13.140: W/System.err(11382): com.google.android.gms.auth.GoogleAuthExcept
我试图在 Android 上使用他们的 sdk 从 Google+ 获取授权 token ,但它总是引发“GoogleAuthException Unknown” 这是我使用的代码: private
我正在尝试通过 Google Plus 登录获取授权代码以在服务器上使用它。 G+ 登录有效,我在设备上登录,但是当我尝试获取 token 时,我收到异常消息 Unknown。这是代码: privat
有关更多上下文,这篇文章遵循 this one . 为了解决我之前的问题,我尝试按照 Tim Bray 在此处提供的解决方案: Verifying Back-End Calls from Androi
我正在尝试使用 Oauth2 对登录到我的设备的 google 用户进行身份验证。我已经创建了客户端 ID,但无法获得预期的结果。 代码是: String mScope="oauth2:server:
我正在实现一个 Android 应用程序,使用户能够直接从该应用程序流式传输到 YouTube channel 。我已经创建了一个 API key 和一个 OAuth 2.0 客户端 ID 但我得到以
登录成功后,我无法检索任何个人资料信息,并且在 GoogleAuthUtil.getToken() 方法上不断收到错误消息。 错误: com.google.android.gms.auth.Googl
我的应用程序允许用户使用 Google Plus 登录,并获取他们的姓名和电子邮件地址。我试图访问 token 。 访问 token 的代码: Toast.makeText(this, "User i
我的目标是在没有任何服务器端工作的情况下获取用户的基本个人资料信息(名字、姓氏等)。而且我不想在用户界面上使用 Google+ 登录按钮。 我可以毫无问题地获取用户的电子邮件。所以下一步是获取访问 t
在我的 Android 应用程序中,我正在尝试获取 google token 以在我的 google 应用引擎后端服务器上进行验证。但我总是得到这个异常(exception): com.google.
我正在编写一个用于上传所选图像的 adroid 应用 到用户的谷歌驱动器。 我已将代码从 git 克隆到另一台机器,然后图像将不再上传。 我得到一个 com.google.android.gms.au
我是一名优秀的程序员,十分优秀!