我遇到了对EatStreet API的AlamoFire请求的问题。我有一个API密钥,并且正确导入了Alamofire。Alamofire API连接和Swift
https://developers.eatstreet.com/endpoint/search
下面是链接到的网站,他们将创建API URL字符串为您服务。
即使这一切,我仍然没有成功
这是样本串
curl -X GET \
-H 'X-Access-Token: __API_EXPLORER_AUTH_KEY__' \
'https://api.eatstreet.com/publicapi/v1/restaurant/search?latitude=40.718293&longitude=-74.002276&method=pickup&pickup-radius=2'
下面是我用我的API和Alamofire请求示例代码。它不断返回结果值为false。任何帮助表示赞赏
import UIKit
import Firebase
import FirebaseDatabase
import FirebaseAuth
import Alamofire
import SwiftyJSON
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(LoginViewController.dismissKeyboard))
//Uncomment the line below if you want the tap not not interfere and cancel other interactions.
tap.cancelsTouchesInView = false
view.addGestureRecognizer(tap)
let apiToContact = "\\ -H 'X-Access-Token: f6565a0360167144' \\'https://api.eatstreet.com/publicapi/v1/restaurant/search?latitude=40.718293&longitude=-74.002276&method=pickup&pickup-radius=2'"
Alamofire.request(apiToContact).validate().responseJSON() { response in
switch response.result {
case .success:
if let value = response.result.value {
let json = JSON(value)
// Do what you need to with JSON here!
// The rest is all boiler plate code you'll use for API requests
print(json)
}
case .failure(let error):
print(error)
}
}
}
//Calls this function when the tap is recognized.
func dismissKeyboard() {
//Causes the view (or one of its embedded text fields) to resign the first responder status.
view.endEditing(true)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
啊刚才读它谢谢 – HiDungLing
@HiDungLing很大,请标记为正确答案;) – xmhafiz