1

我必须在我的问题中添加更多详细信息,所以这是我尝试从我的卖家中心账户获取订单:

    $host                   = 'sellingpartnerapi-na.amazon.com';     // is this the right URL for REST API to get Orders from my seller central account?  
    $accessKey      = 'AK...YOX.........';
    $secretKey      = 'K...........';
    $region             = 'us-east-1'; 
    $service            = 'execute-api';
    
    
    $requestUrl = 'https://sandbox.sellingpartnerapi-na.amazon.com/orders/v0/orders'; // '<full url>';
    $uri = '/orders/v0/orders'; // '<method path>';
    $httpRequestMethod = 'GET'; // '<http verb>';
    
    

我使用了这个示例文件: https ://github.com/avi-wish/aws4-signature-php 不幸的是没有变量 $host 的示例 URL

如果我测试连接,这是我的回应:

Response:403

{
  "errors": [
    {
      "message": "Access to requested resource is denied.",
     "code": "Unauthorized",
     "details": "Access token is missing in the request header."
    }
  ]
}

我在这里找到了一个可能的解决方案:

https://github.com/amzn/ sell-partner-api-docs/issues/52#issuecomment-713522351

但这对我不起作用。

之前创建一个 IAM 用户有必要吗?这是我创建它的方式:
https ://github.com/amzn/ sell-partner-api-docs/blob/main/guides/developer-guide/SellingPartnerApiDeveloperGuide.md#registering-your- sell-partner-api-应用

我想很多人都有同样的问题。希望有人能给我一个提示。

获取访问令牌后,卷曲返回错误:

[message] => Access to requested resource is denied.                    [code] => MissingAuthenticationToken



function get_orders(){
        $this->host = 'https://sellingpartnerapi-na.amazon.com/orders/v0/orders';
        debug('>>get list of orders');
        $data = "x-amz-date&access_token={$this->access_token}";

        $curl = curl_init($this->host . '/orders/v0/orders');
            curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET");
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($curl, CURLOPT_HTTPHEADER, array(
                'Content-Type: application/json;charset=UTF-8')
            );
        
        $result = curl_exec($curl);
        curl_close($curl);
        $obj = json_decode($result,true);
        debug($obj);
    }
4

2 回答 2

2

不幸的是,您提供的有关您想要做什么的信息很少。有两种方法可以授权通过grant-type.

我想您想授权自己而不是供应商。

然后您必须将您的请求发送到以下端点:

api.amazon.com/auth/o2/token

您必须使用api.amazon.com.

请求方法将是POST.

您将参数传递给 http Body: grant_type, refresh_token, client_id, client_secret

请查看以下链接:

连接到销售伙伴 API

以同样的方式完成所有这些操作后,您将得到以下答案:

{
"access_token":"Atza|IwEBIJR-9fxxxxxxxxxxxxxxxxxxxxxx",
"refresh_token":"Atzr|IwEBIxxxxxxxxxxxxxxxxxxxxxxxx",
"token_type":"bearer",
"expires_in":3600
}

现在您可以使用 access_token 对您的请求进行签名。在下文中,我还建议您使用我在另一个答案中的帖子来签署请求并成功发送请求。

答案:64858116

于 2020-11-19T16:14:46.840 回答
0
public function GetAcessToken()
    {
        $RefeshToken = $this->RefreshToken;

        $data = "grant_type=refresh_token" 
        ."&refresh_token=". $RefeshToken
        ."&client_id=".$this->ClientID
        ."&client_secret=".$this->ClientSecret;

        $curl = curl_init($this->UrlForAmazonToken);
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/x-www-form-urlencoded;charset=UTF-8')
        );
        
        $result = curl_exec($curl);
        curl_close($curl);
        $obj = json_decode($result,true);
        
        $this->AccessToken =  $obj['access_token'] ;
 
        return $this->AccessToken;
    }

这个对我有用。

于 2021-11-23T07:11:27.527 回答