gpt4 book ai didi

ios - 在 iOS 上创建 Stripe 收件人时出错

转载 作者:行者123 更新时间:2023-11-29 02:20:57 26 4
gpt4 key购买 nike

我正在使用此代码创建一个 Stripe 收件人:

let name = "John Doe"
let request = NSMutableURLRequest(URL: NSURL(string: "https://api.stripe.com/v1/recipients")!)
let params = "\(stripeKey):&name=\(name)&type=individual&card=tok_15P1vqDxE2HbT5qyw3sI7tku"

request.HTTPMethod = "POST"
request.HTTPBody = params.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue())
{
(url: NSURLResponse!, data: NSData!, error: NSError!) -> Void in

let string = NSString(data: data, encoding: NSUTF8StringEncoding)
println(string)
}

出现这个错误:

"You did not provide an API key. You need to provide your API key in the Authorization header, using Bearer auth (e.g. 'Authorization: Bearer     YOUR_SECRET_KEY'). See https://stripe.com/docs/api#authentication for details, or we can help at https://support.stripe.com/."

我该怎么办?

最佳答案

我与 Stripe 的工作人员交谈过,我能够正确地做到这一点。我在代码中忘记的是标题:

//Getting Recipient
let name = "John Doe"
let request = NSMutableURLRequest(URL: NSURL(string:"https://api.stripe.com/v1/recipients")!)
let stripeKey = "sk_test_XXX"
let params = "name=\(name)&type=individual&card=\(token.tokenId)"


request.setValue("Bearer \(stripeKey)", forHTTPHeaderField: "Authorization") //This is what I had to add

关于ios - 在 iOS 上创建 Stripe 收件人时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28143923/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com