我正在尝试将google登录功能添加到我的应用中。这可以在android模拟器上正常工作,但是我正在无法正常运行的真实设备中运行该应用程序。问题出在登录过程之后,Google重定向到其自己的首页,而不是应用程序。
我要遵循的步骤。
我用来打开google登录页面的功能
const result = await Google.logInAsync({
androidStandaloneAppClientId: '131814552849-bi76mebb3eq5jsdergerdfh6werjd8udpen43.apps.googleusercontent.com',
scopes: ['profile', 'email'],
behavior: 'web
});
app.json
我在certificateHash中使用了Google证书哈希(SHA-1)
"android": {
"package": "com.abc.mycompnay",
"permissions": ["READ_EXTERNAL_STORAGE", "WRITE_EXTERNAL_STORAGE"],
"config": {
"googleSignIn": {
"apiKey": "AIzaSyB6qp9VXGXrtwuihvna40F57xABKXJfEQ",
"certificateHash": "29FD8B159A28F2F48ED3283548NEBFC957F6821D"
}
}
}
Google控制台设置
客户密钥
登录后最终显示自己的主页
答案 0 :(得分:0)
打开gradle并更改重定向方案
android {
defaultConfig {
manifestPlaceholders = [
appAuthRedirectScheme: 'com.example.yourpackagename'
]
}
}
答案 1 :(得分:0)
我设法修复它。以下是我的工作。我通过config中的redirectUrl
import * as AppAuth from 'expo-app-auth';
const result = await Google.logInAsync({
androidStandaloneAppClientId: 'myKey,
iosStandaloneAppClientId: 'myKey,
scopes: ['profile', 'email'],
behavior: 'web',
redirectUrl: `${AppAuth.OAuthRedirect}:/oauthredirect`
});
答案 2 :(得分:0)
好的,我会把它放在这里,因为这花费了我很多生命。如果您碰巧使用 Android 设备对其进行测试:请确保您已选择 Chrome 作为默认浏览器。其他人可能无法正确重定向您!
答案 3 :(得分:0)
在 app.json 中, 包名必须是像com.app.cloneapp这样的所有小写字母