无法从google calender API访问令牌
我正在使用谷歌日历,如何在用户登录时获取访问令牌。
// Display the start dates and event summaries in the UITextView
func displayResultWithTicket(
ticket: GTLServiceTicket,
finishedWithObject response : GTLCalendarEvents,
error : NSError?) {
if let error = error {
showAlert("Error", message: error.localizedDescription)
return
}
print(service.authorizer)
var eventString = ""
if let events = response.items() where !events.isEmpty {
for event in events as! [GTLCalendarEvent] {
let start : GTLDateTime! = event.start.dateTime ?? event.start.date
let startString = NSDateFormatter.localizedStringFromDate(
start.date,
dateStyle: .ShortStyle,
timeStyle: .ShortStyle
)
eventString += "\(startString) - \(event.summary)\n"
}
} else {
eventString = "No upcoming events found."
}
output.text = eventString
}
打印(service.authorizer)
输出:
GTMOAuth2Authentication 0x7fae3d9cc9a0: {accessToken="ya29.CjBCA3-uM-b2vtbvFtYgfS5anHIVaRc7NwHY4pD9uPQEj2phoqk1yjd-TNnsWEz_nSQ", refreshToken="1/pBtww6SXoUZv_9l9L0C4QGGvNoqVWMdIDvCWXeI9Uco", expirationDate="2016-08-17 06:51:43 +0000"}
如何从中获取访问令牌?
我使用此代码获取acessToken: -
print(service.authorizer.description)
let json = service.authorizer.description
let array = json.componentsSeparatedByString("\"")
print(array[1])
但我不认为这是最好的方法,任何人都可以建议更好地解决这个问题