1

私はすでにライブラリ Alamofire をインストールしており、データ API の取得に Get Request メソッドを使用したい

このようなコード:

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 にアクセスするコードに問題があると思います。Oauth1 GetメソッドでAlamofireを使用する方法??

4

0 に答える 0