问题:
在 iOS 应用程序中,我使用 google signIn 来促进获取 authCode 的过程,稍后将其发送到服务器并在 google 日历 API 中交换 refresh_token。坏消息是它user.serverAuthCode
总是为零。
现在发生了什么: 我已经按照谷歌的文档来实现它。此时,当我单击 google 登录按钮时,我会转到一个页面,在该页面中填写我的凭据并同意所有范围。然后它将我重定向回 iOS 应用程序,但我没有得到 authCode。
代码:
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate{
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
if (error == nil) {
print("Authcode is : \(user.serverAuthCode)") // This is nil :(
}
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
GIDSignIn.sharedInstance().clientID = "MY_CLIENT_ID"
GIDSignIn.sharedInstance().delegate = self
GIDSignIn.sharedInstance().scopes.append("https://www.googleapis.com/auth/calendar")
GIDSignIn.sharedInstance().scopes.append("https://www.googleapis.com/auth/calendar.events")
return true
}
}
我还在目标信息中添加了 URL 类型,如谷歌文档中所述
最后,我有一个 viewController 用于GIDSignInButton
启动登录过程。
有什么我想念的吗?我看了一下这篇文章,但我无法解决问题。感谢您的时间!