【问题标题】:PayPal REST API: trying to activate a billing plan, but getting "HTTP/1.1 401 Unauthorized"PayPal REST API:尝试激活计费计划,但得到“HTTP/1.1 401 Unauthorized”
【发布时间】:2017-02-17 13:39:34
【问题描述】:

我正在建立一个电子商务网站,我的客户可以在其中通过 PayPal API 付款。现在,我正在使用 Sandbox 学习它的工作原理;参考本页:https://developer.paypal.com/docs/integration/direct/billing-plans/

我已经满足了先决条件,即创建了一个 PayPal 应用程序, 获得了访问令牌,并进行了 API 调用。然后,我成功制定了计费计划,将示例命令复制并粘贴到页面上,只需替换 Access Token。

现在,我想激活计费方案,但未能成功。

使用的命令再次从页面复制粘贴,如下所示。

curl -v -k -X PATCH https://api.sandbox.paypal.com/v1/payments/billing-plans/P-7DC96732KA7763723UOPKETA/ \
  -H 'X-PAYPAL-OAUTH-CONTEXT: {"consumer":{"accountNumber":1181198218909172527,"merchantId":"5KW8F2FXKX5HA"},"merchant":{"accountNumber":1659371090107732880,"merchantId":"2J6QB8YJQSJRJ"},"apiCaller":{"clientId":"AdtlNBDhgmQWi2xk6edqJVKklPFyDWxtyKuXuyVT-OgdnnKpAVsbKHgvqHHP","appId":"APP-6DV794347V142302B","payerId":"2J6QB8YJQSJRJ","accountNumber":"1659371090107732880"},"scopes":["https://api.paypal.com/v1/payments/.*","https://uri.paypal.com/services/payments/futurepayments","openid"]}' \
  -H 'Content-Type: application/json' \
  -d '[{
  "op": "replace",
  "path": "/",
  "value": {
    "state": "ACTIVE"
  }
}]'

首先,按照指示,我刚刚将计划 ID“P-7DC96732KA7763723UOPKETA”替换为我在之前创建计划的回复中提供的。

*   Trying 173.0.82.78...
* Connected to api.sandbox.paypal.com (173.0.82.78) port 443 (#0)
* TLS 1.2 connection using TLS_RSA_WITH_AES_256_CBC_SHA256
* Server certificate: api.sandbox.paypal.com
* Server certificate: Symantec Class 3 Secure Server CA - G4
* Server certificate: VeriSign Class 3 Public Primary Certification Authority - G5
> PATCH /v1/payments/billing-plans/P-8AX21799EN516221GJMBOECA/ HTTP/1.1
> Host: api.sandbox.paypal.com
> User-Agent: curl/7.43.0
> Accept: */*
> X-PAYPAL-OAUTH-CONTEXT: {"consumer":{"accountNumber":1181198218909172527,"merchantId":"5KW8F2FXKX5HA"},"merchant":{"accountNumber":1659371090107732880,"merchantId":"2J6QB8YJQSJRJ"},"apiCaller":{"clientId":"AdtlNBDhgmQWi2xk6edqJVKklPFyDWxtyKuXuyVT-OgdnnKpAVsbKHgvqHHP","appId":"APP-6DV794347V142302B","payerId":"2J6QB8YJQSJRJ","accountNumber":"1659371090107732880"},"scopes":["ttps://api.paypal.com/v1/payments/.*","ttps://uri.paypal.com/services/payments/futurepayments","openid"]}
> Content-Type: application/json
> Content-Length: 78
>
* upload completely sent off: 78 out of 78 bytes
< HTTP/1.1 401 Unauthorized
< Date: Fri, 17 Feb 2017 12:18:47 GMT
< Server: Apache
< paypal-debug-id: c46e304b4bb46
< Paypal-Debug-Id: c46e304b4bb46
< Set-Cookie: X-PP-SILOVER=name%3DSANDBOX3.API.1%26silo_version%3D1880%26app%3Dplatformapiserv%26TIME%3D669689432%26HTTP_X_PP_AZ_LOCATOR%3D; Expires=Fri, 17 Feb 2017 12:48:47 GMT; domain=.paypal.com; path=/; Secure; HttpOnly
< Set-Cookie: X-PP-SILOVER=; Expires=Thu, 01 Jan 1970 00:00:01 GMT
< Content-Length: 0
< Connection: close
< Content-Type: text/plain; charset=ISO-8859-1
<
* Closing connection 0

我尝试了一些其他参数替换,例如客户端 ID,但没有运气。

我需要替换其他参数吗? 或者,我做错了什么?

【问题讨论】:

  • 您是否使用了正确的访问令牌?
  • 感谢您的帖子。是的,根据我保存的记录,我使用了正确的访问令牌,这是我从先决条件过程中获得的;我想我不会成功地制定计费计划,否则。顺便说一句,我现在遇到的问题 - 激活计费计划 - 不需要访问代码,关于我需要在命令行中输入的命令,如我原来的帖子所示。如有错误请指正。再次感谢!
  • 解决了;请看我自己的答案。您对访问令牌是正确的;我使用的成功命令包括访问令牌。非常感谢您的帮助!
  • 这是我的快乐伙伴!在那里玩得开心编码。

标签: rest api paypal unauthorized


【解决方案1】:

已解决。

On this page, I found simpler and more straightforward command

并由以下组成:

curl -v -X PATCH https://api.sandbox.paypal.com/v1/payments/billing-plans/<Plan ID>/ \
-H "Content-Type:application/json" \
-H "Authorization: Bearer <Access Token>" \
-d '[
  {
  "path":"/",
  "value":{"state":"ACTIVE"},
  "op":"replace"}
]'

得到如下响应:

*   Trying 173.0.82.78...
* Connected to api.sandbox.paypal.com (173.0.82.78) port 443 (#0)
* TLS 1.2 connection using TLS_RSA_WITH_AES_256_CBC_SHA256
* Server certificate: api.sandbox.paypal.com
* Server certificate: Symantec Class 3 Secure Server CA - G4
* Server certificate: VeriSign Class 3 Public Primary Certification Authority - G5
> GET /v1/payments/billing-plans/<Plan ID> HTTP/1.1
> Host: api.sandbox.paypal.com
> User-Agent: curl/7.43.0
> Accept: */*
> Content-Type:application/json
> Authorization: Bearer <Access Token>
> 
< HTTP/1.1 200 OK
< Date: Sun, 19 Feb 2017 11:36:50 GMT
< Server: Apache
< paypal-debug-id: 3ca31778e271e
< Content-Language: *
< Paypal-Debug-Id: 3ca31778e271e
< Set-Cookie: X-PP-SILOVER=name%3DSANDBOX3.API.1%26silo_version%3D1880%26app%3Dplatformapiserv%26TIME%3D1384360280%26HTTP_X_PP_AZ_LOCATOR%3D; Expires=Sun, 19 Feb 2017 12:06:52 GMT; domain=.paypal.com; path=/; Secure; HttpOnly
< Set-Cookie: X-PP-SILOVER=; Expires=Thu, 01 Jan 1970 00:00:01 GMT
< Vary: Authorization
< Content-Length: 1391
< Connection: close
< Content-Type: application/json
< 
* Closing connection 0
{"id":"<Plan ID>","state":"ACTIVE","name":"Sample Plan",
...
"rel":"self","method":"GET"}]}

获得 HTTP 200 和状态“ACTIVE”。

感谢您的帮助,非常感谢!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-09
    • 2023-03-12
    • 2017-06-21
    • 2023-03-23
    • 2015-01-27
    • 2016-04-05
    • 2020-04-13
    • 2014-12-15
    相关资源
    最近更新 更多