Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/95.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios “额外参数”;方法“;随时待命。阿拉莫菲尔_Ios_Swift_Alamofire - Fatal编程技术网

Ios “额外参数”;方法“;随时待命。阿拉莫菲尔

Ios “额外参数”;方法“;随时待命。阿拉莫菲尔,ios,swift,alamofire,Ios,Swift,Alamofire,我正在使用Alamofire向Yelp api发出一个get请求,我得到了我的post请求,但我的get请求不起作用。我已经尝试了从其他问题中读到的所有内容,但仍然没有解决方案。这是我的密码 这是我的发帖请求,正在工作中 class func getAccessToken() { let parameters: Parameters = ["client_id": client_id, "client_secret": client_secret] Alamofire.req

我正在使用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
         }
    }
}
这是我的get请求,我遇到了麻烦

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

谢谢。

您正在传递类
参数
,而不是它的对象
参数

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 {

它应该是
参数
而不是
参数