gpt4 book ai didi

ios - 有没有办法使用 Foursquare API 按价格搜索 field ?

转载 作者:行者123 更新时间:2023-11-28 07:54:43 28 4
gpt4 key购买 nike

我正在使用 Foursquare API 在 Swift 中创建一个 iOS 项目 this API和 SwiftyJSON。有什么方法可以获得与特定价格等级相匹配的 Venue 结果?

我了解如何接收包含价格等级的 field 结果,但是,除了检查价格等级并过滤掉相关的结果外,我不确定如何接收仅与特定价格等级匹配的 field 。

编辑:我当前的代码如下所示:

 func setUpFoursquare(){
let client = FoursquareAPIClient(clientId: "JMBLK0SDZ0N2NF5TG3UCLMOF4FA5FKA14AIOZ4P4TS4MHEWO", clientSecret: "*****")

let parameter: [String: String] = [
"near": "Toronto",//destination!,
"limit": "4",
"query": "sushi",
"price": "1",
];
print("Parameter: \(parameter)");
print("client: \(client)");
//The path is based on the request link. For example, the request link for photos is:
//GET https://api.foursquare.com/v2/venues/VENUE_ID/photos
//So the path would correspond tovenues/VENUE_ID/photos where VENUE_ID is the corresponding ID.
client.request(path: "venues/search", parameter: parameter) { result in
// client.request(path: "venues/categories", parameter: parameter) { result in

switch result {
case let .success(data):
print("Success")
guard let json = try? JSON(data: data) else{
print("\(#function): Unable to retrieve json object")
return
}
print("Json: \(json)")
if json["meta"]["code"] == 200{
self.parse(jsonObject: json)
}
case let .failure(error):
// Error handling
switch error {
case let .connectionError(connectionError):
print(connectionError)
case let .responseParseError(responseParseError):
print(responseParseError) // e.g. JSON text did not start with array or object and option to allow fragments not set.
case let .apiError(apiError):
print(apiError.errorType) // e.g. endpoint_error
print(apiError.errorDetail) // e.g. The requested path does not exist.
}
}//end switch
}//end client.request


}

但是“价格”:“1”参数实际上并没有改变结果。

最佳答案

使用 venues/explore 端点,您可以按价格等级过滤结果。请参阅此处的文档:https://developer.foursquare.com/docs/api/venues/explore

具体来说,您需要使用 price 参数:

Comma separated list of price points. Currently the valid range of price points are [1,2,3,4], 1 being the least expensive, 4 being the most expensive. For food venues, in the United States, 1 is < $10 an entree, 2 is $10-$20 an entree, 3 is $20-$30 an entree, 4 is > $30 an entree.

使用您链接到的 API 包装器,它看起来像这样......

let parameter: [String: String] = [
"ll": "35.702069,139.7753269",
"limit": "10",
"price": "1,2"
];

client.request(path: "venues/explore", parameter: parameter) { result in
// do your SwiftyJSON stuff
}

关于ios - 有没有办法使用 Foursquare API 按价格搜索 field ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48568936/

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