当我尝试使用 Google 登录时 google_sign_in:^6.1.6
我遇到错误
[GSI_LOGGER-OAUTH2_CLIENT]: Popup timer stopped.
[GSI_LOGGER-TOKEN_CLIENT]: Trying to set gapi client token.
[GSI_LOGGER-TOKEN_CLIENT]: The OAuth token was not passed to gapi.client, since the gapi.client library is not loaded in your page.
这是我的代码:
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:google_sign_in/google_sign_in.dart';
final authRepositoryProvider = Provider((ref) {
return AuthRepository(googleSignIn: GoogleSignIn());
});
class AuthRepository {
final GoogleSignIn _googleSignIn;
AuthRepository({
required GoogleSignIn googleSignIn,
}) : _googleSignIn = googleSignIn;
void googleSignIn() async {
try {
final user = await _googleSignIn.signIn();
if (user != null) {
print(user.email);
print(user.displayName);
}
} catch (e) {
print(e);
}
}
}
有人遇到过这个问题并能够解决吗?
我最近在我的项目中使用了这个功能并且它有效
final FirebaseAuth _auth = FirebaseAuth.instance;
final GoogleSignIn _googleSignIn = GoogleSignIn();
Future<String?> signInwithGoogle() async {
try {
final GoogleSignInAccount? googleSignInAccount =
await _googleSignIn.signIn();
final GoogleSignInAuthentication googleSignInAuthentication =
await googleSignInAccount!.authentication;
final AuthCredential credential = GoogleAuthProvider.credential(
accessToken: googleSignInAuthentication.accessToken,
idToken: googleSignInAuthentication.idToken,
);
await _auth.signInWithCredential(credential);
} on FirebaseAuthException catch (e) {
print(e.message);
throw e;
}
}
如需更多帮助,请关注此博客 https://petercoding.com/firebase/2021/05/24/using-google-sign-in-with-firebase-in-flutter/
如果您了解印地语/乌尔都语,请关注此视频以获取最新文档和方法 https://youtu.be/rt7B4tD67Gw