在我的应用程序中。我想使用Google帐户登录任何与我的应用同步他的日历。当我使用谷歌SDK登录时,我会看到像Image下面的某种令牌。但我不知道该怎么做。
我使用以下代码登录。
@IBAction func btnGoogleClicked(){
self.presentViewController(self.createAuthController(), animated: true) {
self.hideAddAccountView();
}
}
//MARK: - Google calendar Method
func createAuthController() -> GTMOAuth2ViewControllerTouch{
let authController : GTMOAuth2ViewControllerTouch;
let arrScopes = NSMutableArray();
arrScopes.addObject(kGTLAuthScopeCalendarReadonly)
arrScopes.addObject("profile")
authController = GTMOAuth2ViewControllerTouch(scope: arrScopes.componentsJoinedByString(" "), clientID: kClientID, clientSecret: nil, keychainItemName: kKeychainItemName, delegate: self, finishedSelector: #selector(HomeVC.viewController(_:auth:error:)))
authController.signIn.shouldFetchGoogleUserProfile = true
return authController;
}
func viewController(vc : GTMOAuth2ViewControllerTouch, auth : GTMOAuth2Authentication,error : NSError?){
if (error != nil) {
AlertView.showOKTitleMessageAlert("Authentication Error", strMessage: error!.localizedDescription, viewcontroller: self)
self.service.authorizer = nil;
}
else {
self.service.authorizer = auth;
print("email - \(auth.userEmail)")
print("userDate - \(auth.userData)")
print("properties = \(auth.properties)")
print("properties = \(vc.signIn.userProfile)")
print("properties = \(vc.signIn.userData)")
currentLoginDictionary = vc.signIn.userProfile
self.dismissViewControllerAnimated(true, completion: nil)
fatchEvents()
}
}
func fatchEvents(){
let query = GTLQueryCalendar.queryForEventsListWithCalendarId("primary")
query.maxResults = 150;
query.timeMin = GTLDateTime.init(date: NSDate(), timeZone: NSTimeZone.localTimeZone())
query.singleEvents = true;
query.orderBy = kGTLCalendarOrderByStartTime;
self.service.executeQuery(query, delegate: self, didFinishSelector: #selector(HomeVC.eventFatchedSuccessfully(_:events:error:)))
}
func eventFatchedSuccessfully(ticket : GTLServiceTicket,events : GTLCalendarEvents,error : NSError?){
print("ticket \(ticket.userData) \(ticket.APIKey)")
}
任何人都可以帮助我。