我已经安装了库Alamofire,我想使用Get Request Method获取数据API
像这样的代码:import UIKit
import Alamofire
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let params = ["oauth_consumer_key":"*********",
"oauth_consumer_secret":"*******",
"oauth_token_key":"********",
"oauth_token_secret": "********",
"oauth_signature_method": "HMAC-SHA1",
"oauth_version": "1.0"] as [String : Any];
Alamofire.request("https://conversation.8villages.com/1.0/contents/articles?state=published", method: .get, parameters: params).responseJSON { response in
print(response.request!) // original URL request
print(response.response!) // HTTP URL response
print(response.data!) // server data
print(response.result) // result of response serialization
if let JSON = response.result.value {
print("JSON: \(JSON)")
}
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
我得到了这样的错误
https://conversation.8villages.com/1.0/contents/articles?state=published&oauth_consumer_key=Sjt29_vS0K6t-QeXsieYn9Kq0.&oauth_consumer_secret=YUVeiF_I5ZEoZLnD66dQ6pBu4Oi6D96NpyRbJ-Suo.&oauth_signature_method=HMAC-SHA1&oauth_token_key=COb34BuiV5bxr7R1l9mDXfw6s.&oauth_token_secret=AZ1HSYNI3d5SyOQY6Uc_L4kimPwylf6ixgISL3BEc.&oauth_version=1.0
<NSHTTPURLResponse: 0x60000002bd80> { URL: https://conversation.8villages.com/1.0/contents/articles?state=published&oauth_consumer_key=Sjt29_vS0RmK6t-QeXsieYn9Kq0.&oauth_consumer_secret=YUVeUSiF_I5ZEoZLnD66dQ6pBu4Oi6D96NpyRbJ-Suo.&oauth_signature_method=HMAC-SHA1&oauth_token_key=COb34BuiV5bxr7Rdq1l9mDXfw6s.&oauth_token_secret=AZ1DSHSYNI3d5SyOQY6Uc_L4kimPwylf6ixgISL3BEc.&oauth_version=1.0 } { status code: 400, headers {
Connection = "keep-alive";
"Content-Length" = 2;
"Content-Type" = "application/json";
Date = "Mon, 10 Apr 2017 06:53:24 GMT";
Server = nginx;
} }
2 bytes
SUCCESS
JSON: {
}
我认为我的代码与Alamofire Oauth1访问API有些不对劲。 所以如何使用Alamofire和Oauth1获取方法 ??