Amazon使用javaSDK調用SP-API獲取賣家分析數據(二)ordersV0Api

1.獲取Amazon官方SDK

不會的同窗請點擊這裏java

官方文檔git

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.jsongithub

請選中帶有x-amazon-spds-sandbox-behaviors的內容爲測試請求要求。json

4.實操

4.1 getOrders

請求要求:api

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

請求要求:markdown

image-20210707161543229.png

請求代碼:ide

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

請求結果:oop

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邀請進羣~

相關文章
相關標籤/搜索