在iOS中使用Google SignIn后无法获取Authcode(Swift)

康斯坦丁诺斯(Kwnstantinos Nikoloutsos)

问题:在iOS应用中,我使用google signIn来简化authCode的获取过程,该authCode稍后发送到服务器中,并与google calendar API中的refresh_token交换。坏消息user.serverAuthCode是总是零。

现在发生了什么:我已经按照Google的文档进行了实施。此时,当我单击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
    }

 }

我还按照Google文档中的说明在目标信息中添加了网址类型

最后,我有一个viewController,用于GIDSignInButton启动登录过程。


我有什么想念的吗?我看了这篇文章,但无法解决问题。感谢您的时间!

康斯坦丁诺斯(Kwnstantinos Nikoloutsos)

经过一段时间的搜索后发现:)

添加后解决的问题:

GIDSignIn.sharedInstance()?.serverClientID = "SERVER_CLIENT"

如果您不知道如何获取这些信息:SERVER_CLIENT与CLIENT_ID

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章