我正在尝试制作联系人管理/社交网络应用程序,并在遵循Ray Wenderlich website的教程后使用AeroGearOAuth2。我已修改它以尝试并首先验证用户,然后在swift中使用闭包我试图检索此用户的联系人。我使用了谷歌OAuth2游乐场来玩游戏范围和GET网址,但在我的内部响应中继续接收'nil'的值。我觉得我必须忘记那些痛苦明显的事情。我不完全确定如何附加'Gdata-version:3'的标题,所以我有所了解。这可能是问题所在。这是我检索联系人的功能:
@IBAction func getGoogleContacts(sender: AnyObject) {
let googleConfig = GoogleConfig(
clientId: ${MY_CLIENT_ID},
scopes:["https://www.googleapis.com/auth/userinfo.email","https://www.google.com/m8/feeds/contacts/default/full"])
let gdModule = AccountManager.addGoogleAccount(googleConfig)
self.http.authzModule = gdModule
let headers = ["Gdata-Version ": "3.0"]
let contactsUrl:String = "https://www.google.com/m8/feeds/contacts/default/full"
let emailUrl:String = "https://www.googleapis.com/oauth2/v2/userinfo";
self.http.GET(emailUrl,completionHandler: {(response, error) in
if (error != nil) {
self.presentAlert("Error", message: "\(error!.localizedDescription) + \(response)")
} else {
let userEmail: AnyObject! = response!["email"]!
self.http.GET(contactsUrl,parameters:headers, completionHandler: {
(response2,error2) in
if (error != nil) {
self.presentAlert("Error",message:"\ (error2!.localizedDescription)" )
}else {
println(response2)
}
})
self.presentAlert("Success", message: "Successfully retrieved contact: + \(userEmail)")
}
})