[英]PayPal Transaction Search API: PERMISSION_DENIED, No Permission for the requested operation
我正在编写一项服务(在 .NET Core 3.1 和 Refit 中,如果重要的话),它从我的 PayPal 业务帐户中提取给定日期范围内的交易活动,以在管理仪表板上使用。 目前我正在关注这里的教程:
https://developer.paypal.com/docs/api/get-an-access-token-postman/
和这里:
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 --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'
错误:
{
"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"
}
错误中的信息链接开始谈论第 3 方权限,我不确定这是否适用,因为它是我的企业帐户。 有人有想法么? 我在 PayPal 中检查了我的应用程序的交易历史记录,所以我很迷茫。
提前致谢
您需要范围https://uri.paypal.com/services/reporting/search/read
.. 如果 oauth2 响应中没有它,请仔细检查您的 REST 应用程序的权限。
现有访问令牌缓存 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 应用程序的新范围。
我遇到了同样的问题,经过多次环顾后,我通过以下方式修复了它:
<?
$clientId = 'AfC.....';
$secret = "EJs......";
$url_base= 'https://api-m.sandbox.paypal.com/';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url_base . "v1/oauth2/token");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json','Accept-Language: en_US'));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $clientId.":".$secret);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
$result = curl_exec($ch);
if(empty($result))die("Error: No response.");
else
{//token received
$json = json_decode($result, true);
print_r($json['scope']);
//place a call
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url_base . "v1/reporting/transactions?start_date=2020-12-01T00:00:00-0700&end_date=2020-12-30T23:59:59-0700&fields=all");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json',"Authorization: Bearer ".$json['access_token']."", 'Accept-Language: en_US', 'Content-Type: application/json'));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($test));
$result = curl_exec($ch);
if(empty($result))die("Error: No response.");
else
{
$result= json_decode($result, true);
print_r($result);
}
}//end of token received
curl_close($ch);
希望这对其他人有帮助,我知道这个问题很老了!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.