postman 从FedEx获取OAuth令牌以用于Track API

lf5gs5x2  于 2023-04-11  发布在  Postman
关注(0)|答案(2)|浏览(220)

我试图获得OAuth令牌以获得对一些FedEx API的授权访问权限(例如跟踪货物的Track API),但我得到了401 (NOT.AUTHORIZED.ERROR -> "The given client credentials were not valid. Please modify your request and try again") error.(目前,我正在使用Postman尝试和测试API。
以下是我使用的URL,由FedEx提供:https://apis-sandbox.fedex.com/oauth/token
我已经遵循了(根据我的理解)应该如何设置body和headers:

Headers: Content-Type: application/x-www-form-urlencoded
Body: x-www-form-urlencoded (Postman option): 
   grant_type: client_crendentials
   client_id: ***PROJECT_API_KEY
   client_secret: ***PROJECT_SECRET KEY

发送后,我只收到上面的错误消息。我检查/双重检查了我的API密钥,但我似乎无法让它通过。有什么想法吗?

postman settings:
POST - URL https://apis-sandbox.fedex.com/oauth/token
Headers - Content-Type: application/x-www-form-urlencoded
Body - x-www-form-urlencoded: 
   grant_type: client_credentials
   client_id: *******
   client_secret: *******

(资料来源:https://developer.fedex.com/api/en-us/catalog/authorization/v1/docs.html

von4xj4u

von4xj4u1#

创建新账户时,沙盒API凭据不能立即使用。我花了**〉1小时**才收到FedEx的注册完成邮件,之后沙盒凭据才生效。

qncylg1j

qncylg1j2#

今天第一次尝试了这个,设置了我的帐户并获得了我的联邦快递凭据。我不得不使用Safari,Chrome不起作用,可能是因为我的广告拦截器。首先在联邦快递开发人员网站“尝试此API”上测试了OAuth请求,它立即起作用。即使在几个小时后,它在Postman中也不起作用。我可以使用cURL从沙箱中获得OAuth令牌。

$url = "https://apis-sandbox.fedex.com/oauth/token";

$payload = "grant_type=client_credentials&client_id=xxxx&client_secret=yyyy";

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$json = json_decode($response, true);
curl_close($ch);
print_r($json);

$token = $json['access_token'];

相关问题