ios - 无法从 Paypal SDK 获取访问 token 。遇到异常说 “Authentication needed”

标签 ios paypal oauth

我正在使用 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 "

我通过此链接获得了以键值组合的形式传递所有数据的引用。

https://developer.paypal.com/webapps/developer/docs/integration/direct/make-your-first-call/#get-an-access-token

所以我是否以正确的方式传递了客户端 ID 和密码,或者缺少了一些东西...... 或者有没有其他方法可以做到这一点......

最佳答案

访问 token 的生成是服务器到服务器的调用,而不是从您的应用程序本身完成的。此外,这样做时,客户端 ID 和密码将在 header 中发送,而不仅仅是作为键>值发布。可以找到验证移动支付的步骤here .

关于ios - 无法从 Paypal SDK 获取访问 token 。遇到异常说 “Authentication needed”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25059178/

相关文章:

ios - 如果存在 UIApplicationLaunchOptionsLocationKey,则启动 Cordova iOS 应用程序

php - Paypal IPN 设置 : "ship to" ZIP code and auto calculation of shipping charges

android - 如何在我的网络应用程序中使用来自 AccountManager 的 Google token ? (Rails with omniauth-google-oauth2)

ios - 无法将类型 'P?' 的返回表达式转换为返回类型 'UIViewController'

python - 了解netlib fftpack的结果

ios - 如何使 UIAlertController 消息可选择

php - 如何防止导致 301 重定向的 URL 出现在浏览器历史记录中?

ruby - 使用信用卡执行付款

python - 禁用或限制/o/应用程序(django rest framework,oauth2)

php - 指导我使用 phpleague 库实现 Oauth2 PHP 服务器