我是廣告,點擊一下吧!
標籤
#Flutter (15) 、 #PHP (9) 、 #Laravel (7) 、 #Dart (5) 、 #MySQL (5) 、 #Mac (4) 、 #VS Code (2) 、 #IDE (2) 、 #List (2) 、 #Android (2) 、 #Carbon (2) 、 #Linux (2) 、 #Shell Script (2) 、 #MySQL 效能 (1) 、 #Pagination (1) 、 #Cursor Pagination (1) 、 #LaTeX (1) 、 #個人空間 (1) 、 #Android Splash Screen (1) 、 #createFromTimestamp (1) 、 #資安 (1) 、 #Google Maps Static API (1) 、 #Mac M1 (1) 、 #floorMonth (1) 、 #subMonthNoOverflow (1) 、 #addMonthNoOverflow (1) 、 #subMonth (1) 、 #addMonth (1) 、 #keytool (1) 、 #Play App Signing (1)功能 | 6.x | 7.x |
---|---|---|
GoogleSignIn 建構 | GoogleSignIn(scopes: ['email']) | GoogleSignIn.instance.initialize(serverClientId: ...) |
signIn | await _googleSignIn.signIn() | await GoogleSignIn.instance.authenticate(scopeHint: ['email'], nonce: ...) |
silent signIn | signInSilently() | attemptLightweightAuthentication() |
access token | 直接在 authentication | 透過 authorizationClient.authorizationForScopes() |
try {
final GoogleSignIn _googleSignIn = GoogleSignIn(scopes: ['email']);
final GoogleSignInAccount? account = await _googleSignIn.signIn();
if (account != null) {
return GoogleUserDataModel(
account.id,
(await account.authentication).idToken ?? '',
(await account.authentication).accessToken ?? '',
account.displayName ?? '',
account.email,
account.photoUrl,
);
}
} catch (error) {
return null;
}
return null;
try {
await GoogleSignIn.instance.initialize(
serverClientId: '<google-services.json → oauth_client → client_type: 3 → client_id>',
nonce: '<optional, provide your own nonce value if required>',
);
GoogleSignInAccount account = await GoogleSignIn.instance.authenticate(scopeHint: ['email']);
GoogleSignInClientAuthorization? tokenInfo = await account.authorizationClient.authorizationForScopes(['email']);
return GoogleUserDataModel(
account.id,
account.authentication.idToken ?? '',
tokenInfo?.accessToken ?? '',
account.displayName ?? '',
account.email,
account.photoUrl,
);
} catch (error) {
return null;
}
iOS 滿順利的,只要 pod update 一下就好
pod update GoogleSignIn AppAuth
Android 就花了點時間,選完帳號無反應,出現 Exception: GoogleSignInExceptionCode.canceled
。
I/flutter (14536): GoogleSignInException(code GoogleSignInExceptionCode.canceled, activity is cancelled by the user., null)
出現這個 Exception 這一定是使用者取消,沒設定好也可能會出現
Some configuration errors will cause the underlying Android CredentialManager SDK to return a “canceled” error in this flow, and unfortunately the google_sign_in plugin has no way to distinguish this case from the user canceling sign-in, so cannot return a more accurate error message.
有幾種可能:
google-services.json
檔案中 oauth_client
裡 client_type
為 3 的 client_id
。Your google-services.json contains a web OAuth client, which should be an oauth_client entry with client_type: 3. This should have been created automatically when enabling Google Sign In using the Firebase console, but if not (or if it was later removed), add a web app to the project and then re-download google-services.json.