gpt4 book ai didi

ios - 调用中的额外参数 "method"。阿拉莫菲尔

转载 作者:可可西里 更新时间:2023-11-01 01:22:35 26 4
gpt4 key购买 nike

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

这是我正在运行的发帖请求。

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

谢谢。

最佳答案

您正在传递类 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 {

关于ios - 调用中的额外参数 "method"。阿拉莫菲尔,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43246193/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com