我希望使用OAuth1
构建项目,我发现了这样的签名请求:
Authorization:
OAuth oauth_consumer_key="xvz1evFS4wEEPTGEFPHBog",
oauth_nonce="kYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg",
oauth_signature="tnnArxj06cWHq44gCs1OSKk%2FjLY%3D",
oauth_signature_method="HMAC-SHA1",
oauth_timestamp="1318622958",
oauth_token="370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb",
oauth_version="1.0"
但是,我怎么能
oauth_signature,oauth_nonce,oauth_timestamp?
如何在没有Postman的情况下制作它?
答案 0 :(得分:0)
使用库OAuthSwiftAlamofire
无需手动创建 oauth_signature , oauth_nonce 和 oauth_timestamp 。检查示例代码
let oauthswift = self.getAuth1Object()
oauthswift.client.credential.oauthToken = kAuthToken
oauthswift.client.credential.oauthTokenSecret = kAuthTokenSecret
let sessionManager = SessionManager.default
sessionManager.adapter = OAuthSwiftRequestAdapter(oauthswift)
let api = sessionManager.request(strURL,method: .post, parameters: parameters, encoding: JSONEncoding.default,headers: ["Content-Type" :"application/json"])
这是你的 getAuth1Object()
func getAuth1Object() -> OAuth1Swift {
let oauthswift = OAuth1Swift(
consumerKey: "put your consumer key here",
consumerSecret: "put your consumer secret here",
requestTokenUrl: "",
authorizeUrl: "",
accessTokenUrl: ""
)
return oauthswift
}