如何将令牌密钥和令牌密钥传递给Alamofire请求?

时间:2017-04-27 04:29:22

标签: ios swift oauth alamofire

我有Consumer Key,Consumer Secret,Token Key和Token Secret来获取Data API。在邮递员中这样:

我必须在上面的捕获邮递员中获取我的API数据。那么我有Alamofire的方法请求:

    Alamofire.request("https://conversation.8villages.com/1.0/contents/articles?state=published", headers: headers).responseJSON { response in
            print("test", response.request!)  // original URL request
            print("ini responseny", response.response!) // HTTP URL response
            print("test", response.data!)     // server data
            print("test", response.result)   // result of response serialization

            if let JSON = response.result.value {
                print("JSON: \(JSON)")
            }
        }

所以,我不知道如何在方法get中添加或传递我的令牌。请有人帮助我。

我正在使用 OAuthSwift Alamofire

1 个答案:

答案 0 :(得分:0)

试试这个

let headers: HTTPHeaders = [
    "Authorization": "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==",
    "Accept": "application/json"
]

Alamofire.request("https://httpbin.org/headers", headers: headers).responseJSON { response in
    debugPrint(response)
}