0
oath_signatureを作成したいと思います。 は、私は私のoath_signatureが正しいSwiftでoath_signatureを作成するには?
<message>Invalid signature: oauth_signature 'd1b9eb5c8a5700e17d69894358fac6b7abe4a0ac'</message>
ではないことを応答を得る誰かがoath_signatureを作成するために私を助けることができますか?私は多くの解決策を探したが、何も働かなかった。私は間違っているの?
私は次のように私のSignatureBaseStringを作成します。
var signatureBase: String = ""
signatureBase += http_method + "&"
signatureBase += normalizedUrl + "
signatureBase += normalizedRequestParameters
signatureBase = signatureBase.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)!
私は次のように作成する鍵と秘密を持つ文字列:私はそのコードを生成
var stringFormat: String =
consumer_key.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)! +
"&" +
consumer_secret.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)!
署名:
signature = signatureBase.hmac(algorithm: .SHA1, key: stringFormat)
文字列の拡張子は他の投稿のものです(CommonHMAC in Swift)
私はそのコードを送信要求:
let requestUrl = normalizedUrl
let postString = normalizedRequestParameters + "&" + "oauth_signature=" + signature.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)!
//Send Request
var done = false
var request = URLRequest(url: URL(string: requestUrl)!)
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
request.httpMethod = http_method
request.httpBody = postString.data(using: .utf8)
print("Send request")
var requestResponse = ""
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data, error == nil else {// check for fundamental networking error
print("error=\(error)")
return
}
if let httpStatus = response as? HTTPURLResponse, httpStatus.statusCode != 200 {// check for http errors
print("statusCode should be 200, but is \(httpStatus.statusCode)")
print("response = \(response)")
}
let responseString = String(data: data, encoding: .utf8)
done = true
requestResponse = responseString!
//print("responseString = \(responseString)")
}
task.resume()
//Wait for response
repeat {
RunLoop.current.run(until: Date(timeIntervalSinceNow: 0.1))
} while !done
print(requestResponse)
あなたの答えをありがとう、私はそれを確認します。私は自分の問題が署名の最後の生成だと思う。 – MMbach