【问题标题】:How to fetch google contacts into an iOS application如何将谷歌联系人提取到 iOS 应用程序中
【发布时间】:2017-03-18 18:24:22
【问题描述】:

我阅读了以下链接,现在我明白我需要调用 api 来获取联系人。由于我是 Swift3 的新手,有人可以指导我如何做到这一点。我在某处读到 Almofire 和 Swifty json 会有所帮助,我也读过 GData 也会有所帮助。我有点困惑。请指导我。

Google Contacts API

【问题讨论】:

标签: ios iphone cocoapods swift3 google-contacts-api


【解决方案1】:

我实际上也被困在这个问题上,找不到解决方案,但我最终弄明白了。您首先需要通过 Google Sign In 进行身份验证,然后将 accessToken 传递到此端点:

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()

【讨论】:

    【解决方案2】:

    您可能想尝试Google Sign-In for iOS,让用户使用他们已经使用并信任的注册系统(即他们的 Google 帐户)快速、安全地进入您的应用。这个 Google 登录视频 - series #1series #2series #3 将帮助您了解 Google 登录在 iOS 中的实现,您如何在 iOS 上使用 Google 登录与 Google Drive 等其他服务?等等。

    以下是一些可以提供帮助的教程和参考资料:

    最后这里有一些相关的 SO 问题供参考 - How to fetch gmail Contacts in iOS application using google contacts api?Get Google contacts using API on iOS

    希望这会有所帮助。

    【讨论】:

    • 感谢您的链接和信息。它帮助很大,但我仍然无法将联系人提取到我的应用程序中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多