【发布时间】:2017-07-21 01:29:29
【问题描述】:
我在向 EatStreet API 发送 AlamoFire 请求时遇到问题。我有一个 API 密钥,并且我已经正确导入了 Alamofire。
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.
}
}
【问题讨论】: