我正在用GIDSignInButton我的用户签到谷歌.问题是,我不确定如何保存当前用户,以便每个用户每次打开应用程序时都不必登录.我尝试过使用signInSilently()但The operation couldn’t be completed. (com.google.GIDSignIn error -4.)每次都得到.
头文件中的错误说明了这一点:
// Indicates there are no auth tokens in the keychain. This error code will be returned by
// signInSilently if the user has never signed in before with the given scopes, or if they have
// since signed out.
kGIDSignInErrorCodeHasNoAuthInKeychain = -4,
Run Code Online (Sandbox Code Playgroud)
就我而言,用户已经使用给定的范围登录,但他们还没有退出.所以我不确定是什么导致了这个错误.
用户登录后,如何将该实例保存到我signInSilently()之后可以使用的位置?是否还涉及刷新和访问令牌?
我已将Google登录集成到我的iOS应用中.我想访问用户的性别和年龄.文档不够清晰,无法看到如何执行此操作.我已经想出我应该要求合适的范围.我没有在文档中找到正式的范围列表,我不知道应该使用哪个范围.此外,我不知道如何在获取数据时检索数据.如果有人帮我从谷歌获取此信息,我将不胜感激.谢谢!
这是我的代码:
func googleLogin() {
self.appDelegate.setIdentityAvailableValue(false)
GIDSignIn.sharedInstance().clientID = kClientId
GIDSignIn.sharedInstance().shouldFetchBasicProfile = true
GIDSignIn.sharedInstance().delegate = self
GIDSignIn.sharedInstance().uiDelegate = self
GIDSignIn.sharedInstance().signInSilently()
}
func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!, withError error: NSError!) {
if (error == nil) {
let idToken = user.authentication.idToken
let url = NSURL(string: "https://www.googleapis.com/oauth2/v3/userinfo?access_token=\(user.authentication.accessToken)")
let session = NSURLSession.sharedSession()
session.dataTaskWithURL(url!, completionHandler: { (data, response, error) -> Void in
//UIApplication.sharedApplication().networkActivityIndicatorVisible = false
if error != nil {
print("dataTaskWithURL error \(error)")
}
else {
do {
let userData = try NSJSONSerialization.JSONObjectWithData(data!, options:[]) as? …Run Code Online (Sandbox Code Playgroud)