【问题标题】:Unable to get access token from Paypal sdk. Got an Exception says “Authentication needed”无法从 Paypal sdk 获取访问令牌。出现异常说“需要身份验证”
【发布时间】:2014-07-31 12:43:44
【问题描述】:

我正在使用 PayPal SDK 进行自适应支付...我在

中收到 PayPal Payment Success 消息
 - (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 被调用... 我得到错误:

“需要验证”

我得到了参考,以通过此链接以键值组合的形式以帖子形式传递所有数据。

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

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

【问题讨论】:

    标签: ios paypal oauth


    【解决方案1】:

    访问令牌的生成是服务器到服务器的调用,不是从您的应用程序本身完成的。此外,当这样做时,客户端 ID 和机密会在标头中发送,而不仅仅是作为 key>value 发布。验证移动支付的步骤可以在here找到。

    【讨论】:

    • 我不知道如何从这些 curl syntex 中制作正确的 url。请你帮帮我。
    • 我不确定我是否理解您的要求。您不会创建一个 URL 来简单地重定向/发布到。您将信息发送回您的服务器并使用服务器端脚本进行付款验证。
    猜你喜欢
    • 2016-09-15
    • 2017-07-30
    • 2015-06-21
    • 2021-04-21
    • 2019-06-29
    • 2018-09-07
    • 2017-07-03
    • 1970-01-01
    • 2020-07-30
    相关资源
    最近更新 更多