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

Getting error while creating Stripe Recipients on iOS

我正在使用此代码创建 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 documentations了吗? StripePublishableKey 与您的 API 密钥相同。

// AppDelegate.m

#import "AppDelegate.h"
#import "Stripe.h"

NSString * const StripePublishableKey = @"pk_test_6pRNASCoBOKtIshFeQd4XMUh";

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  [Stripe setDefaultPublishableKey:StripePublishableKey];
  return YES;
}

@end

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

//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