【问题标题】:Extra argument "method" in call. Alamofire调用中的额外参数“方法”。阿拉莫菲尔
【发布时间】:2017-04-06 05:12:33
【问题描述】:

我正在使用 Alamofire 向 Yelp api 发出 get 请求,我的 post 请求正在运行,但我的 get 请求无法正常工作,我已经尝试了从其他问题中读取的所有内容,但仍然没有解决方案。这是我的代码。

这是我正在工作的发帖请求。

class func getAccessToken() {
     let parameters: Parameters = ["client_id": client_id, "client_secret": client_secret]
     Alamofire.request("https://api.yelp.com/oauth2/token", method: .post, parameters: parameters, encoding: URLEncoding.default, headers: nil).response {
         response in
         print("Request: \((response.request)!)")
         print("Response: \((response.response)!)")

         if let data = response.data {
         let dict = try! JSONSerialization.jsonObject(with: data, options: []) as! NSDictionary
         print("Access Token: \((dict["access_token"])!)")
         self.accessToken = (dict["access_token"])! as? String
         self.tokenType = (dict["token_type"])! as? String
         }
    }
}

这是我遇到问题的获取请求。

class func getRestaurents(searchTerm: String) {
        let parameters: Parameters = ["term": searchTerm, "location": "******"]
        let headers: HTTPHeaders = [tokenType!: accessToken!]
        Alamofire.request("https://api.yelp.com/v3/businesses/search", method: .get, parameters: Parameters, encoding: JSONEncoding.default, headers: headers).response {
            response in
            if let data = response.data {
                let dict = try! JSONSerialization.jsonObject(with: data, options: [] as! [NSDictionary])
                print(dict)
            }
        }
    }

谢谢。

【问题讨论】:

  • 应该是parameters 而不是Parameters

标签: ios swift alamofire


【解决方案1】:

您正在传递类 Parameters 而不是它的对象 parameters

Alamofire.request("https://api.yelp.com/v3/businesses/search", method: .get, parameters: Parameters, encoding: JSONEncoding.default, headers: headers).response {

应该是:

Alamofire.request("https://api.yelp.com/v3/businesses/search", method: .get, parameters: parameters, encoding: JSONEncoding.default, headers: headers).response {

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-03
    • 2017-02-07
    • 2016-12-06
    • 1970-01-01
    • 1970-01-01
    • 2017-01-27
    相关资源
    最近更新 更多