ios - 在 iOS 中谷歌登录后无法获取 Authcode (swift)
问题描述
问题:
在 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
启动登录过程。
有什么我想念的吗?我看了一下这篇文章,但我无法解决问题。感谢您的时间!
解决方案
经过一段时间的搜索,找到了解决方案:)
添加后解决的问题:
GIDSignIn.sharedInstance()?.serverClientID = "SERVER_CLIENT"
如果您不知道如何获取这些:SERVER_CLIENT vs CLIENT_ID
推荐阅读
- javascript - 用另外两个 observable 喂一个 observable
- c++ - 使用 MSVC 获得“实例化导致未执行的类型”
- oauth-2.0 - 如何使用 OAuth2、密码流和 OTP?
- kubernetes - 如何获取 kubernetes 作业的开始、结束时间和状态
- python - QThread:使用 GUI python 进行线程化
- azure - 如何将多个 json 文件导入/上传到 Azure Devops Pipeline Release and Builds?
- python - 不和谐.py | 如何获取公会中所有语音频道的列表
- three.js - 编辑器中 MeshStandardMateiral 中的模糊 envmap
- android - 将 .gradle 文件夹包含到我的 gitignore 中是否安全?如果是这样,为什么它不包含在由 flutter create myapp 命令生成的默认 gitignore 文件中
- javascript - 不同浏览器中的日期输入格式