[英]Google Drive API Android: stuck on login
I'm trying to implement the Drive API for Android to back-up a file to the AppFolder. 我正在尝试为Android实现Drive API,以将文件备份到AppFolder。 I'm using the tutorial on Using the Google APIS Client Library for Java to integrate with Drive on Android and used some code snippets from the Quickstart .
我正在使用有关使用Java的Google APIS客户端库与Android上的云端硬盘集成的教程,并使用了快速入门中的一些代码段。
.connect()
call is unsuccesful with error code SIGN_IN_REQUIRED
, which seems logical to me. .connect()
调用失败,错误代码为SIGN_IN_REQUIRED
,这对我来说似乎很合理)。 onResume
method calls .connect()
again. onResume
方法再次调用.connect()
。 .connect()
call fails with the same error code ( SIGN_IN_REQUIRED
) and the process repeats. .connect()
调用失败,并显示相同的错误代码( SIGN_IN_REQUIRED
),然后重复该过程。 In the API Manager of the Google Developer Console, I created a project for this app. 在Google Developer Console的API Manager中,我为此应用程序创建了一个项目。 In that project, I created an "OAuth 2.0 client ID" for the app with the debug package name and the SHA-1 for the debug key.
在该项目中,我为应用程序创建了一个“ OAuth 2.0客户端ID”,其中包含调试包名称和SHA-1作为调试键。 In the manifest of the Quickstart, I didn't see the Client ID of said credential used anywhere.
在快速入门的清单中,我看不到任何地方都使用了该凭据的客户端ID。
Is this a known issue or did I make a mistake somewhere? 这是一个已知问题,还是我在某个地方犯了错误?
Edit: 编辑:
I built the original Quickstart from scratch, and the error still occurred. 我从头开始构建了原始的快速入门,但仍然发生错误。 It might therefore be an issue with the API Console rather than a client issue.
因此,这可能是API控制台的问题,而不是客户端的问题。
Not the solution I was expecting but here it is: 不是我期望的解决方案,但这里是:
It turned out Android Studio was NOT signing my app with the debug key located at ~/.android/debug.keystore
, but with a different key. 事实证明,Android Studio
~/.android/debug.keystore
位于~/.android/debug.keystore
的调试密钥对我的应用程序进行签名,而是使用了其他密钥。
Without knowing which key it was, I was able to figure out its SHA-1 using the method described in this SO question . 在不知道它是哪个密钥的情况下,我能够使用此SO问题中描述的方法找出其SHA-1。
This is because you didn't generate proper apk with proper SHA1 key or package name which need to be registered in the Google API console. 这是因为您没有使用正确的SHA1密钥或程序包名称生成正确的apk,而该密钥或程序包名称需要在Google API控制台中注册。 The code from [Google android-quickstart] is 100% correct.
来自[Google android-quickstart]的代码是100%正确的。 The onResume method calls .connect() again is due to your SHA1 key or package name is not matched with the API console.
由于您的SHA1键或软件包名称与API控制台不匹配,因此onResume方法再次调用.connect()。
To solve the problem: (1) You should generate the Sha1 for your app first.. if you are using Android Studio and developing the app, please follow this to get the default sha1 of your app. 解决此问题的方法:(1)您应首先为您的应用程序生成Sha1。.如果您使用的是Android Studio并正在开发该应用程序,请按照以下步骤获取应用程序的默认sha1。 [Remember don't use live sha1 key, otherwise you will get stuck on login!]
[请记住不要使用实时sha1键,否则登录时会卡住!]
(2) Follow this to create your OAuth client ID by using default sha1. (2)按照此步骤使用默认的sha1创建OAuth客户端ID。 (3) Run [Google android-quickstart] again.
(3)再次运行[Google android-quickstart]。
*Note: You do not have to copy any API client ID to your manifest or activity, because you are supposed to register your app with the specified package name and Sha1 Key in the API console successfully, so that Google can detect these things automatically when the app is started. *注意:您不必将任何API客户端ID复制到清单或活动中,因为应该在API控制台中成功使用指定的程序包名称和Sha1键注册应用,以便Google可以在出现以下情况时自动检测到这些信息该应用程序已启动。
That's right, exactly as mentioned above. 是的,完全如上所述。 When authenticating the GoogleDrive API, this API requests SHA1 from the application, and when we install the application in test mode on the emulator the authentication does not work, because SHA1 does not correspond to SHA1 of the keystore.
在对GoogleDrive API进行身份验证时,此API向应用程序请求SHA1,并且当我们在模拟器上以测试模式安装应用程序时,身份验证将不起作用,因为SHA1与密钥库的SHA1不对应。 To solve this problem we must configure our GRADLE in this way.
为了解决这个问题,我们必须以这种方式配置GRADLE。
signingConfigs{
key{
keyAlias 'your key alias'
keyPassword 'your keypassword'
storeFile file('keystore path')
storePassword 'your storepassword'
}
}
buildTypes {
debug{
signingConfig signingConfigs.key
}
}
buildTypes {
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
debuggable false
useProguard true
}
debug {
shrinkResources true
minifyEnabled true
debuggable true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
useProguard true
}
}
When you publish the application remove this part of the code 发布应用程序时,请删除此部分代码
signingConfigs{
key{
keyAlias 'your key alias'
keyPassword 'your keypassword'
storeFile file('keystore path')
storePassword 'your storepassword'
}
}
buildTypes {
debug{
signingConfig signingConfigs.key
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.