How to fetch google contacts into an iOS applicati

2019-09-11 01:46发布

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 Contacts API

2条回答
来,给爷笑一个
2楼-- · 2019-09-11 02:18

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()
查看更多
可以哭但决不认输i
3楼-- · 2019-09-11 02:30

You might want to try Google Sign-In for iOS, get users into your apps quickly and securely, using a registration system they already use and trust—their Google account. This Google Sign-in videos - series #1, series #2 and series #3 will help you understand the implementation of Google SignIn in iOS, how do you use Google Sign in on iOS with another service like Google Drive? and more.

Here are some tutorials and reference that can help:

Lastly here are some related SO question for refrence - How to fetch gmail Contacts in iOS application using google contacts api? and Get Google contacts using API on iOS

Hope this helps.

查看更多
登录 后发表回答