【问题标题】:How to use Yelp api v3 in swift如何在 swift 中使用 Yelp api v3
【发布时间】:2023-03-18 11:35:02
【问题描述】:

长话短说,我希望能够获得有关位置的评论、图像等,并将它们添加到地图中。使用 Yelp 的 api v3 似乎是做到这一点的最佳方式,但我很难找到体面的/更新的/工作文档。

我看过这里: https://github.com/codepath/ios_yelp_swift/tree/master/Yelp

但它已经过时(api和swift版本)

我确实设法找到了这个更新的文档。在 v3 上: https://github.com/Yelp/yelp-fusion/tree/master/fusion/swift

但代码不起作用。

我还查看了关于 yelp api 的几乎所有问题/线程,但大多数问题都已过时或从未回答。

但是根据我对查看其他问题的理解,为了使用 api,我必须创建一个 HTTP GET 请求,更改授权,并使用 url 解码数据:https://api.yelp.com/v3(但使用我想要的条款等) 但 yelp 提供的文档不包括这些?

我的问题是,谁能提供正确使用 v3 api 的完整示例(或链接)或提供有关如何使用它的一些说明?

任何帮助将不胜感激

【问题讨论】:

    标签: swift yelp


    【解决方案1】:

    花了一些时间才弄到它。

        fileprivate func fetchYelpBusinesses(latitude: Double, longitude: Double) {
            let apikey = "YourAPIKey"
            let url = URL(string: "https://api.yelp.com/v3/businesses/search?latitude=\(latitude)&longitude=\(longitude)")
            var request = URLRequest(url: url!)
            request.setValue("Bearer \(apikey)", forHTTPHeaderField: "Authorization")
            request.httpMethod = "GET"
    
            URLSession.shared.dataTask(with: request) { (data, response, error) in
                if let err = error {
                    print(err.localizedDescription)
                }
                do {
                    let json = try JSONSerialization.jsonObject(with: data!, options: []) as! [String: Any]
                    print(">>>>>", json, #line, "<<<<<<<<<")
                } catch {
                    print("caught")
                }
                }.resume()
        }
    
    

    【讨论】:

      【解决方案2】:

      对于其他想要使用 Yelp 的 api 但正在努力寻找适当文档的人,我发现您可以安装“CDYelpFusionKit”,而不是使用“yelpapi”吊舱。它有更多的文档并且更易于使用。

      文档链接:https://github.com/chrisdhaan/CDYelpFusionKit

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-02-05
        • 2019-02-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-08-18
        • 2017-05-22
        • 1970-01-01
        相关资源
        最近更新 更多