我使用GoogleSignIn为Android应用程序实现了Google SSO。 我使用了In Intent和startActivityForResult方法: 身份验证流如下所示:
val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken("client_id")
.requestServerAuthCode("client_id", true)
.requestScopes(Scope("email profile openid https://www.googleapis.com/auth/youtube https://www.googleapis.com/auth/youtube.readonly"))
.requestEmail()
.build()
binding.googleSignInButton.setOnClickListener{
Timber.i("${gso.scopes}")
val signInIntent = GoogleSignIn.getClient(this, gso)?.signInIntent
startActivityForResult(signInIntent, RC_SIGN_IN)
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
.....doesn't matter, I tested. never reached here.
}
这种方法在我测试过的仿真器设备API 29上运行良好。 但是,在API 30,Pixel 3仿真器上,登录确认屏幕将在短暂加载后重复出现: enter image description here 单击“允许”后,该屏幕将变为一个小的加载屏幕,并且该确认屏幕将重新出现。
onActivityResult
从未达到。
也:仅对于API 30: 在Google开发者控制台的OAuth同意屏幕中添加youtube api作用域之前, 我收到以下行为:
我还在清单中添加了查询:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="com.example.myapp" />
</intent>
</queries>
<application
android:allowBackup="true"
android:fullBackupContent="@xml/backup_descriptor"
android:allowClearUserData="true"
android:name="com.example.myapp.application.YoutubeApplication"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<!-- Main Activity-->
<activity
android:name="com.example.myapp.application.activities.MainActivity"
android:label="@string/app_name"
android:launchMode="singleTop" />
<!-- Login Activity-->
<activity
android:name="com.example.myapp.application.activities.LoginActivity"
android:label="@string/app_name"
android:windowSoftInputMode="stateHidden">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="com.example.myapp"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
答案 0 :(得分:0)
很显然,早期版本存在一些配置错误,我在模拟器上重新安装了该应用程序,从而解决了该问题。