我正在使用 PayPal SDK 进行自适应支付...我在
中收到 PayPal 支付成功消息 - (void)payPalPaymentViewController:(PayPalPaymentViewController *)paymentViewController didCompletePayment:(PayPalPayment *)completedPayment {
NSLog(@"PayPal Payment Success!");
[self sendCompletedPaymentToServer:completedPayment]; // Payment was processed successfully; send to server for verification and fulfillment
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)sendCompletedPaymentToServer:(PayPalPayment *)completedPayment {
// TODO: Send completedPayment.confirmation to server
NSLog(@"Here is your proof of payment:\n\n%@\n\nSend this to your server for confirmation and fulfillment.", completedPayment.confirmation);
payId=[[completedPayment.confirmation objectForKey:@"response"] objectForKey:@"id"];
[self callForAccessToken]; ///////calll webservice to get access token
}
- (void)callForAccessToken {
NSString *shippingURL=[NSString stringWithFormat:@"https://api.sandbox.paypal.com/v1/oauth2/token"];
ASIFormDataRequest *shippingRequest = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:shippingURL]];
[shippingRequest setRequestMethod:@"POST"];
shippingRequest.tag=1010;
[shippingRequest setPostValue:@"application/json" forKey:@"Accept"];
[shippingRequest setPostValue:@"en_US" forKey:@"Accept-Language"];
NSString *clientIDSecret=[NSString stringWithFormat:@"kClientID:kClientsecret"];
[shippingRequest setPostValue:clientIDSecret forKey:@"clientId:secret"];
[shippingRequest setPostValue:@"client_credentials" forKey:@"grant_type"];
[shippingRequest setDelegate:self];
[shippingRequest setDidFinishSelector:@selector(uploadFinishedLocation:)];
[shippingRequest setDidFailSelector:@selector(uploadFailLocation:)];
[shippingRequest startAsynchronous];
}
- (void)uploadFinishedLocation:(ASIHTTPRequest *)requestObj {
NSString *response = [requestObj responseString];
NSLog(@"\n\nReq tag %ld Response string in Payment Didload %@\n\n",(long)requestObj.tag,response);
}
- (void)uploadFailLocation:(ASIHTTPRequest *)requestObj {
NSLog(@"%@",requestObj.error.description);
}
当我执行代码时 uploadFailLocation
被调用...
我得到错误:
" Authentication needed "
我通过此链接获得了以键值组合的形式传递所有数据的引用。
所以我是否以正确的方式传递了客户端 ID 和密码,或者缺少了一些东西...... 或者有没有其他方法可以做到这一点......
最佳答案
访问 token 的生成是服务器到服务器的调用,而不是从您的应用程序本身完成的。此外,这样做时,客户端 ID 和密码将在 header 中发送,而不仅仅是作为键>值发布。可以找到验证移动支付的步骤here .
关于ios - 无法从 Paypal SDK 获取访问 token 。遇到异常说 “Authentication needed”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25059178/