我正在尝试在 iOS 中实施 AWS Mobile Hub。单击“使用 Google 登录”按钮时,我在身份浏览器上看到了我的身份 ID。这里没有问题。然后我想访问 GIDGoogleUser。我初始化了 GIDGoogleUser 但我无法访问用户信息:
let googleUser = GIDGoogleUser.init()
然后我检查了用户是否使用 google 登录:
if(AWSGoogleSignInProvider.init().isLoggedIn){
print("Success")
}else{
print("Authentication error")
}
我在 xcode 中看到“身份验证错误”输出。我的错误在哪里?我怎样才能得到谷歌用户的电子邮件和全名?
AppDelegate.swift :
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
AWSGoogleSignInProvider.sharedInstance().setScopes(["profile","email", "openid"])
AWSSignInManager.sharedInstance().register(
signInProvider: AWSGoogleSignInProvider.sharedInstance())
let didFinishLaunching = AWSSignInManager.sharedInstance().interceptApplication(
application, didFinishLaunchingWithOptions: launchOptions)
if (!isInitialized) {
AWSSignInManager.sharedInstance().resumeSession(completionHandler: {
(result: Any?, error: Error?) in
print("Result: \(result) \n Error:\(error)")
})
isInitialized = true
}
return didFinishLaunching
}