如何将Google联系人获取到iOS应用程序中 [英] How to fetch google contacts into an iOS application
本文介绍了如何将Google联系人获取到iOS应用程序中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我阅读了以下链接,现在我知道我需要进行api调用来获取联系人。由于我是Swift3的新手,有人可以指导我如何执行此操作。我在某处读到Almofire和Swifty json会有所帮助,并且我也读过GData也将有所帮助。我有点困惑。
I read the below link and now I understood that I need to make an api call to fetch the contacts. As I am new to Swift3 could someone guide me how to do this. I read somewhere that Almofire and Swifty json would help and I also read GData also will help. I am little confused. Please guide me.
推荐答案
我实际上也被卡住了,找不到一个解决方案,但我最终弄清楚了。您首先需要通过Google登录进行身份验证,然后将accessToken传递到此端点:
I was actually stuck on this too and couldn't find a solution but I ended up figuring it out. You first need to authenticate with Google Sign In and then pass the accessToken into this endpoint:
let urlString = ("https://www.google.com/m8/feeds/contacts/default/full?alt=json&max-results=5000&access_token=\(GIDSignIn.sharedInstance().currentUser.authentication.accessToken!)")
guard let url = URL(string: urlString) else { return }
URLSession.shared.dataTask(with: url, completionHandler: {
(data, response, error) in
if(error != nil){
print("error")
}else{
do{
let json = try JSONSerialization.jsonObject(with: data!, options:[]) as! [String : AnyObject]
//parse JSON
}catch let error as NSError{
print(error)
}
}
}).resume()
这篇关于如何将Google联系人获取到iOS应用程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文