gpt4 book ai didi

ios - Swift 中的 Google SingIn 获取个人资料信息

转载 作者:行者123 更新时间:2023-11-28 06:55:10 34 4
gpt4 key购买 nike

我使用 google+ 登录来获取 AppDelegate 中的用户个人资料信息。

如何在 viewController 中访问用户个人资料信息?

AppDelegate代码:

func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!,
withError error: NSError!) {
if (error == nil) {
// Perform any operations on signed in user here.
let userId = user.userID // For client-side use only!
let idToken = user.authentication.idToken // Safe to send to the server
let name = user.profile.name
let email = user.profile.email
// [START_EXCLUDE]

print(userId)

NSNotificationCenter.defaultCenter().postNotificationName(
"ToggleAuthUINotification",
object: nil,
userInfo: ["statusText": "Signed in user:\n\(name)"])
// [END_EXCLUDE]
} else {
print("\(error.localizedDescription)")
// [START_EXCLUDE silent]
NSNotificationCenter.defaultCenter().postNotificationName(
"ToggleAuthUINotification", object: nil, userInfo: nil)
// [END_EXCLUDE]
}
}

最佳答案

I think you try this. you will get definite result 
remember to import some library

import AddressBook
import MediaPlayer
import AssetsLibrary
import CoreLocation
import CoreMotion
/
/
//MARK: Google Login
@IBAction func btnActionGoogleLogin(sender : UIButton)
{
var googleSignIn: GPPSignIn!
googleSignIn = GPPSignIn.sharedInstance();
googleSignIn.shouldFetchGooglePlusUser = true;
googleSignIn.clientID = "";
googleSignIn.shouldFetchGoogleUserEmail = true;
googleSignIn.shouldFetchGoogleUserID = true;
googleSignIn.scopes = [kGTLAuthScopePlusLogin];
googleSignIn.scopes = ["profile"]
googleSignIn.delegate = self;
googleSignIn.authenticate();
}

//MARK: G+ Delegate
func finishedWithAuth(auth: GTMOAuth2Authentication!, error: NSError!) {
let plusService :GTLServicePlus = GTLServicePlus.init()
plusService.retryEnabled = true
plusService.authorizer = GPPSignIn.sharedInstance().authentication
plusService.apiVersion = "v1"

let query : GTLQueryPlus = GTLQueryPlus.queryForPeopleGetWithUserId("me") as! GTLQueryPlus

plusService.executeQuery(query) { (ticket,person, error) -> Void in
if ((error) != nil) {
//Handle Error
} else {
NSLog("Email= %@", GPPSignIn.sharedInstance().authentication.userEmail)
NSLog("GoogleID=%@", person.identifier)
print(person)
print(person.displayName)
}
}

}
func didDisconnectWithError(error: NSError!) {

}
}

关于ios - Swift 中的 Google SingIn 获取个人资料信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33832966/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com