Amazon使用javaSDK调用SP-API获取卖家分析数据(二)ordersV0Api

·  阅读 555

1.获取Amazon官方SDK

不会的同学请点击这里

官方文档

2.获得的效果如下

@Test
public void test01(){
  //1.连接到spApi
  //1.1配置自己的AWS凭证
  AWSAuthenticationCredentials awsAuthenticationCredentials = AWSAuthenticationCredentials.builder()
    .accessKeyId("you accessKeyId")
    .secretKey("you secretKey")
    .region("us-east-1")
    .build();
  //1.2配置您的AWS凭证提供商
  AWSAuthenticationCredentialsProvider awsAuthenticationCredentialsProvider = AWSAuthenticationCredentialsProvider.builder()
    .roleArn("you roleArn")//IAM角色
    .roleSessionName("you roleSessionName")
    .build();
  //1.3配置LWA凭证
  LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
    .clientId("you clientId")
    .clientSecret("you clientSecret")
    .refreshToken("you refreshToken")
    .endpoint("https://api.amazon.com/auth/o2/token")//LWA验证服务器URI
    .build();
  OrdersV0Api ordersV0Api = new OrdersV0Api.Builder().awsAuthenticationCredentials(awsAuthenticationCredentials)
    .awsAuthenticationCredentialsProvider(awsAuthenticationCredentialsProvider)
    .lwaAuthorizationCredentials(lwaAuthorizationCredentials)
     //本次试验为测试环境
    .endpoint("https://sandbox.sellingpartnerapi-na.amazon.com")
    .build();
复制代码

3.参考OrdersV0.json文件发送测试请求

OrdersV0.json

请选中带有x-amazon-spds-sandbox-behaviors的内容为测试请求要求。

4.实操

4.1 getOrders

请求要求:

image-20210707161420668.png

请求代码:

List<String> marketplaceIds = Arrays.asList("ATVPDKIKX0DER");
GetOrdersResponse orders = null;
try {
  orders = ordersV0Api.getOrders(marketplaceIds, "TEST_CASE_200", null, null, null, null, null, null, null, null, null, null, null, null);
} catch (ApiException e) {
  e.printStackTrace();
  System.out.println("orders.getErrors().toString() = " + orders.getErrors().toString());
}
System.out.println("orders.getPayload().getOrders() = " + orders.getPayload().getOrders());
复制代码

请求结果:

image-20210707154513364.png

4.2 getOrder

请求要求:

image-20210707161543229.png

请求代码:

GetOrderResponse order = null;
try {
  order = ordersV0Api.getOrder("TEST_CASE_200");
} catch (ApiException e) {
  e.printStackTrace();
}
System.out.println("order.getPayload() = " + order.getPayload());
复制代码

请求结果:

image-20210707161020256.png

4.3 getOrderBuyerInfo

请求要求:

image-20210707161226878.png

请求代码:

GetOrderBuyerInfoResponse order = null;
        try {
            order = ordersV0Api.getOrderBuyerInfo("TEST_CASE_200");
        } catch (ApiException e) {
            e.printStackTrace();
        }
        System.out.println("order.getPayload() = " + order.getPayload());
复制代码

请求结果:

image-20210707161605765.png

4.4 getOrderAddress

请求要求:

image-20210707161713212.png

请求代码:

GetOrderAddressResponse order = null;
try {
    order = ordersV0Api.getOrderAddress("TEST_CASE_200");
} catch (ApiException e) {
    e.printStackTrace();
}
System.out.println("order.getPayload() = " + order.getPayload());
复制代码

请求结果:

image-20210707161826713.png

4.5 getOrderItems

请求要求:

image-20210707162754954.png

请求代码:

GetOrderItemsResponse order = null;
try {
  order = ordersV0Api.getOrderItems("TEST_CASE_200",null);
} catch (ApiException e) {
  e.printStackTrace();
}
System.out.println("order.getPayload() = " + order.getPayload());
复制代码

请求结果:

image-20210707163020121.png

4.6 getOrderItemsBuyerInfo

请求要求:

image-20210707163136287.png

请求代码:

GetOrderItemsBuyerInfoResponse order = null;
try {
  order = ordersV0Api.getOrderItemsBuyerInfo("TEST_CASE_200",null);
} catch (ApiException e) {
  e.printStackTrace();
}
System.out.println("order.getPayload() = " + order.getPayload());
复制代码

请求结果:

image-20210707163309545.png

到此官方文档的六个接口都以测试完毕!



PS:大家看了后觉得对自己有帮助可以三连留言,欢迎提出宝贵意见,如想进行技术交流欢迎加入Amazon各类API开发交流群!请添加技术人员微信:x118422邀请进群~

分类:
后端
标签:
收藏成功!
已添加到「」, 点击更改