Ios “额外参数”;方法“;随时待命。阿拉莫菲尔
我正在使用Alamofire向Yelp api发出一个get请求,我得到了我的post请求,但我的get请求不起作用。我已经尝试了从其他问题中读到的所有内容,但仍然没有解决方案。这是我的密码 这是我的发帖请求,正在工作中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
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 {
它应该是
参数
而不是参数