首页
\
问答
\
如何从iOS / Objective-C对Stripe API进行POST调用(How to make a POST call to the Stripe API from iOS / Objective-C)
如何从iOS / Objective-C对Stripe API进行POST调用(How to make a POST call to the Stripe API from iOS / Objective-C)
我正在尝试创建一个对Stripe的POST调用,并且无法确定如何正确地进行调用。 这是API规范:
POST https://api.stripe.com/v1/recipients curl https://api.stripe.com/v1/recipients \ -u sk_test_4TyIk8adGJTfvHq9YDt4raCx: \ -d "name=John Doe" \ -d type=individual \ -d tax_id=000000000 \ -d "email=test@example.com" \ -d "description=Recipient for John Doe"
api的参考资料如下: https : //stripe.com/docs/api/curl#create_recipient
到目前为止,这是我的代码:
-(void)createRecipientREST:(STPToken *)token { NSString *name = @"John Doe"; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://api.stripe.com/v1/recipients"]]; NSString *params = [NSString stringWithFormat:@"%@:&name=%@&type=individual&card=%@",kStripeSecretKey,name,token.tokenId]; request.HTTPMethod = @"POST"; request.HTTPBody = [params dataUsingEncoding:NSUTF8StringEncoding]; [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { if (error) { NSLog(@"ERROR: %@",error); } else { NSLog(@"%@", response); } }]; }
这是回复:
<NSHTTPURLResponse: 0x10cfcb880> { URL: https://api.stripe.com/v1/recipients } { status code: 400, headers { "Access-Control-Allow-Credentials" = true; "Access-Control-Allow-Methods" = "GET, POST, HEAD, OPTIONS, DELETE"; "Access-Control-Max-Age" = 300; "Cache-Control" = "no-cache, no-store"; "Content-Length" = 187; "Content-Type" = "application/json;charset=utf-8"; Date = "Fri, 15 Aug 2014 16:23:23 GMT"; Server = nginx; "Strict-Transport-Security" = "max-age=31556926; includeSubDomains"; "Stripe-Version" = "2014-08-04"; } }
但我正在寻找这样的回应:
{ "id": "rp_14Rb9D4UNKEkOFM8A3mxaavE", "object": "recipient", "created": 1408072379, "livemode": true, "type": "individual", "description": "Recipient for John Doe", "email": "test@example.com", "name": "John Doe", "verified": false, "metadata": {}, "active_account": null, "cards": { "object": "list", "total_count": 0, "has_more": false, "url": "/v1/recipients/rp_14Rb9D4UNKEkOFM8A3mxaavE/cards", "data": [] }, "default_card": null }
我应该如何修改我的代码以获得所需的响应? 提前谢谢! :)
I'm trying to create a POST call to Stripe and having trouble figuring out how to make the call correctly. Here's the API specs:
POST https://api.stripe.com/v1/recipients curl https://api.stripe.com/v1/recipients \ -u sk_test_4TyIk8adGJTfvHq9YDt4raCx: \ -d "name=John Doe" \ -d type=individual \ -d tax_id=000000000 \ -d "email=test@example.com" \ -d "description=Recipient for John Doe"
Refrence for api is here: https://stripe.com/docs/api/curl#create_recipient
Here's my code so far:
-(void)createRecipientREST:(STPToken *)token { NSString *name = @"John Doe"; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://api.stripe.com/v1/recipients"]]; NSString *params = [NSString stringWithFormat:@"%@:&name=%@&type=individual&card=%@",kStripeSecretKey,name,token.tokenId]; request.HTTPMethod = @"POST"; request.HTTPBody = [params dataUsingEncoding:NSUTF8StringEncoding]; [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { if (error) { NSLog(@"ERROR: %@",error); } else { NSLog(@"%@", response); } }]; }
Here's the response:
<NSHTTPURLResponse: 0x10cfcb880> { URL: https://api.stripe.com/v1/recipients } { status code: 400, headers { "Access-Control-Allow-Credentials" = true; "Access-Control-Allow-Methods" = "GET, POST, HEAD, OPTIONS, DELETE"; "Access-Control-Max-Age" = 300; "Cache-Control" = "no-cache, no-store"; "Content-Length" = 187; "Content-Type" = "application/json;charset=utf-8"; Date = "Fri, 15 Aug 2014 16:23:23 GMT"; Server = nginx; "Strict-Transport-Security" = "max-age=31556926; includeSubDomains"; "Stripe-Version" = "2014-08-04"; } }
But I'm looking for a response like this:
{ "id": "rp_14Rb9D4UNKEkOFM8A3mxaavE", "object": "recipient", "created": 1408072379, "livemode": true, "type": "individual", "description": "Recipient for John Doe", "email": "test@example.com", "name": "John Doe", "verified": false, "metadata": {}, "active_account": null, "cards": { "object": "list", "total_count": 0, "has_more": false, "url": "/v1/recipients/rp_14Rb9D4UNKEkOFM8A3mxaavE/cards", "data": [] }, "default_card": null }
How should I modify my code to get the desired response? Thanks ahead of time! :)
原文:https://stackoverflow.com/questions/25344115
更新时间:2022-12-30 06:12
最满意答案
相关问答
更多-
不要忘记GPS不精确定位。 通常会偏离几米,所以很自然会有这样的错误读数。 虽然旧的LocationManager具有minDistance设置,但遗憾的是LocationRequest没有。 几种解决方案:如果速度为零,您可以检查速度,这可能表示用户实际上没有移动。 您也可以手动检查旧位置是否与新位置几乎相同(在您的情况下,0.3m似乎是一个很好的阈值)并丢弃该读数。 最后但并非最不重要的是,您可以设置ActivityRecognitionApi活动侦听器以确定用户实际上是在移动还是静止。 Don't f ...
-
Facebook Open Graph API位置搜索所有朋友的照片(Facebook Open Graph API location search for all friends photos)[2022-06-07]
不幸的是,你上一个问题的答案是肯定的......像Scope这样的应用程序正在努力借用时间。 去年四月,facebook推出了v2.0,并表示只允许现有的应用程序使用v1.0,而4月份之后调用1.0的行为与调用2.0的行为相同。 你可以在这里阅读更多内容: https : //developers.facebook.com/docs/apps/changelog#v2_0_permissions and here: stack overflow question re:friends birthdays U ... -
正如我之前提到的那样,正如@Sap 上面的评论所提到的,Geo Search是如何在开发服务器上运行的。 As I indicated earlier and as mentioned in the comment by @Sap above, it is how Geo Search work on the development server.
-
我认为这是一个错误,报告了新的缺陷问题https://code.google.com/p/googleappengine/issues/detail?id=9335 。 dev服务器的临时解决方案 - 找到google.appengine.api.search模块(search.py),并通过添加内联来修补函数_DecodeUTF8,如下所示: def _DecodeUTF8(pb_value): """Decodes a UTF-8 encoded string into unicode.""" ...
-
从两个位置获取距离(Get distance from two location)[2022-07-09]
请仔细阅读此链接。 这段代码是成功运行在我的应用程序 http://ckpatel.blog.com/category/android-gps/ please Read carefully this link. this code is successfull run in my apps http://ckpatel.blog.com/category/android-gps/ -
是。 Overpass API具有“Around”功能,可以完成此操作(搜索给定点半径范围内的项目)。 您可以将其与其他要求相结合(例如,获取特定项目类型的列表): http://wiki.openstreetmap.org/wiki/Overpass_API#Around 例如,使用OverPass Turbo Api(列出“Manzanares,西班牙”附近的所有城镇,纬度和经度,半径为150公里, 试试吧 !):
使用Facebook搜索API获取位置或坐标特定帖子(Fetch location or coordinates specfic posts using facebook search api)[2022-08-21]
可以走FB图以获得类似event , place , checkin等类型的地点和坐标。 例如: 搜索( 链接 ): https://developers.facebook.com/tools/explorer?method=GET&path=search%3Fq%3Dconference%26type%3Devent 然后选择一个结果并执行( 链接 ): https://developers.facebook.com/tools/explorer?method=GET&path=463944956965 ...使用Facebook Graph API按位置搜索公共事件(Search for public events by location using the Facebook Graph API)[2022-06-28]
这曾经工作过(或者如果你有一个v2.0应用程序,它仍然可以工作到2016年8月7日,并且事件是由一个位置/场地设置的页面创建的),如下所述 Facebook Graph API获取纬度和经度的所有事件 例如。 使用Graph API本身,无法在一个查询中搜索附近的事件。 你能做的是 搜索附近的地方 查询1.找到的每个地方的事件 请记住,你必须过滤自己过关事件等等。遗憾的是效率非常低...... 编辑2017-12-20 您可以在此用例中使用https://github.com/tobilg/facebook ...您可以搜索位置或搜索用户,但绝对不能搜索“区域内的所有用户”。 Facebook上的Graph搜索可以处理更多您无法通过API获得的内容。 考虑隐私,我不希望任何应用程序知道我是否在附近,甚至没有授权应用程序;) Facebook文档: https : //developers.facebook.com/docs/graph-api/using-graph-api/v2.2#search 要获取用户所在的locatoin,您需要查看用户参考: https : //developers.facebook.co ...你必须自己计算距离。 您可以使用几何库和computeDistanceBetween方法。 例如: var latlng = new google.maps.LatLng(51.474634, -0.195791); 然后在地理编码器中: var distance = google.maps.geometry.spherical.computeDistanceBetween(latlng, results[0].geometry.location); 您需要将这些标记及其距离存储在一个数组中,如果希望按 ...相关文章
更多- 《iPhone开发视频教程:iOS开发Objective-C视频教程》完整版
- 《Objective-C 程序设计(第4版)》扫描版[PDF]
- [ios视频教程] 无限互联ios视频教程全集之objective-c部分
- 《渥瑞达:Objective-C软件开发视频教程(完整版)》共八天更新完毕
- Objective C--享元模式
- 浅谈iOS与社交化网络
- iOS设备的越狱方法
- 广州iOS培训李刚老师iOS基础强化营授课视频教程
- 《国内首部基于iOS平台下iphone、ipad应用开发-iOS5剖析(新增IOS5项目实战:秦朝史话小说项目)》更新项目第9课[压缩包]
- 关于微信检测SDK应用的原理浅析(iOS)
最新问答
更多- 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
- 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
- OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
- 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
- codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
- 在计算机拍照在哪里进入
- 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
- No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
- 单页应用程序:页面重新加载(Single Page Application: page reload)
- 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
- System.StackOverflow错误(System.StackOverflow error)
- KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
- 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
- android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
- TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
- 企业安全培训的各项内容
- 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
- C#类名中允许哪些字符?(What characters are allowed in C# class name?)
- NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
- 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
- 将多个行和可变行移动到列(moving multiple and variable rows to columns)
- 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
- 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
- Angular $资源不会改变方法(Angular $resource doesn't change method)
- 在Angular 5中不是一个函数(is not a function in Angular 5)
- 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
- 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
- 常见的python rpc和cli接口(Common python rpc and cli interface)
- Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
- 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)