问题描述
我使用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作用域之前, 我收到以下行为:
- 出现第一个确认页面,其中包含我请求的所有范围 在我的gso中
- 我点击允许
- 第二个确认页面仅显示基本范围[openid电子邮件配置文件](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>
解决方法
很显然,早期版本存在一些配置错误,我在模拟器上重新安装了该应用程序,从而解决了该问题。