PayPal 交易搜索 API:PERMISSION_DENIED,没有请求操作的权限

2023-12-30

我正在编写一项服务(在 .NET Core 3.1 和 Refit 中),该服务从我的 PayPal 企业帐户中提取给定日期范围内的交易活动,以便在管理仪表板上使用。目前我正在关注这里的教程:

https://developer.paypal.com/docs/api/get-an-access-token-postman/ https://developer.paypal.com/docs/api/get-an-access-token-postman/

和这里:

https://developer.paypal.com/docs/api/transaction-search/v1/ https://developer.paypal.com/docs/api/transaction-search/v1/

第一部分,我可以很好地获得授权密钥(使用curl或postman,curl如下

curl --location --request POST 'https://api.paypal.com/v1/oauth2/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Authorization: Basic <my client id>:<my secret>' \
--header 'Content-Type: application/x-www-form-urlencoded' \

// not sure what this is, postman specific maybe? 
--header 'Cookie: tsrce=devdiscoverynodeweb; ts=vr%3D0cee9361171ac120001362adffec14c3%26vreXpYrS%3D1679730671%26vteXpYrS%3D1585061694%26vt%3D0cee9390171ac120001362adffec14c2' \
--data-urlencode 'grant_type=client_credentials'

这在邮递员和我的自定义服务中都为我提供了一个身份验证令牌。接下来,当我尝试提取交易(在 Postman 和代码中)时,出现错误

cUrl:

curl --location --request GET 'https://api.paypal.com/v1/reporting/transactions?start_date=2020-03-01T00:00:00Z&end_date=2020-03-31T23:59:59Z' \
--header 'Authorization: Bearer <my token>' \
// Postman???
--header 'Cookie: tsrce=devdiscoverynodeweb; ts=vr%3D0cee9361171ac120001362adffec14c3%26vreXpYrS%3D1679730671%26vteXpYrS%3D1585061694%26vt%3D0cee9390171ac120001362adffec14c2'

Error:

{
    "localizedMessage": "No permission for the requested operation. ",
    "suppressed": [],
    "name": "PERMISSION_DENIED",
    "message": "No permission for the requested operation. ",
    "details": [
        {
            "field": null,
            "value": null,
            "location": null,
            "issue": "No permission for the requested operation. "
        }
    ],
    "information_link": "https://developer.paypal.com/docs/classic/products/permissions/",
    "debug_id": "7e315038e8073"
}

错误中的信息链接开始讨论第三方权限,我不确定该权限是否适用,因为它是我的企业帐户。有人有主意吗?我在 PayPal 的应用程序上检查了交易历史记录,所以我不知所措。

提前致谢


你需要范围https://uri.paypal.com/services/reporting/search/read..如果 oauth2 响应中没有它,请仔细检查您的REST应用程序的权限 https://developer.paypal.com/dashboard/applications.

刷新访问令牌

现有的访问令牌会缓存 9 小时,因此,如果您已经请求了 API 令牌,然后刚刚将此权限添加到您的应用程序中,则该权限的新范围最多可能需要 9 小时才能反映在下一代令牌中。

为了避免等待 9 小时,您可以使用以下命令终止现有的缓存令牌:

curl -X POST https://api.sandbox.paypal.com/v1/oauth2/token/terminate \
     -u "yourclientid:yoursecret" \
     -d "token=REPLACE_WITH_YOUR_TOKEN"

终止后,您下一次获取令牌的调用将获取新生成的令牌,包括刚刚添加到 REST 应用程序的新范围。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

PayPal 交易搜索 API:PERMISSION_DENIED,没有请求操作的权限 的相关文章

随机推荐