[英]Flutter Web Google Sign In
我嘗試在 Flutter Web 中使用 Google 實現登錄。 我使用GoogleSignn 4.1.1和Firebase Auth 0.15.4 。 我沒有收到任何錯誤消息。 它只是不彈出。
google-signin-client_id
的<meta>
標簽 final FirebaseAuth _auth = FirebaseAuth.instance;
FirebaseUser user = await _auth.currentUser();
if (user != null) {
log.d('alreadyLoggedIn');
} else {
final GoogleSignIn _googleSignIn = GoogleSignIn(clientId: Constants.GOOGLE_SIGN_IN_CLIENT_ID);
final GoogleSignInAccount googleUser = await _googleSignIn.signIn();
final GoogleSignInAuthentication googleAuth =
await googleUser.authentication;
final AuthCredential credential = GoogleAuthProvider.getCredential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
await _auth.signInWithCredential(credential);
user = await _auth.currentUser();
assert(user.email != null);
assert(user.displayName != null);
assert(!user.isAnonymous);
assert(await user.getIdToken() != null);
}
return user;
}
我希望有人知道如何解決這個問題。
您是否遵循了此頁面中的所有說明(包括將 OAuth ID 添加到 index.html)? https://pub.dev/packages/google_sign_in_web
您從https://console.developers.google.com/apis/credentials獲取您的客戶 ID
您還必須像這樣從終端運行,以便在調試時在本地主機上運行:
flutter run -d chrome --web-hostname localhost --web-port 5000
默認授權端口為 5000,您可以在獲得 CLIENT ID 的同一頁面上添加其他 URI(例如8764367243864-987523.apps.googleusercontent.com),它位於“Authorised JavaScript origins” https://console.developers.google 下。 com/apis/憑證)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.