时间一晃而过又过了两周,博客园更新的速度确实有点慢,今天我要分享的是对请求报告的调用。
在文档中,相信大家也看了下面这个流程图吧?
相关流程,在文档中也有细说,我就不一一去Copy了:http://docs.developer.amazonservices.com/zh_CN/reports/Reports_Overview.html
接着我们说ReportTypes 枚举,请求报告类型有很多种,我们可以可以使用 ReportTypes 枚举,来指定报告类型,从而获取我们想要得到的相关数据。
ReportTypes枚举有以下分类:
具体大家可以参考以下详细文档:
http://docs.developer.amazonservices.com/zh_CN/reports/Reports_ReportType.html
获取相关的报告也分两种形式,有的报告通过:RequestReport 操作,有的是通过ManageReportSchedule或者GetReportList的API接口来获取。
接下来就以GetReportList为例
1 public class ReportClient
2 { 3 4 private ReportClient() { } 5 6 7 public ReportClient(string reportType) 8 { 9 this.ReportType = reportType; 10 } 11 12 public string ReportType { get; set; } 13 14 /// <summary> 15 /// 获得账户信息 16 /// </summary> 17 private static AccountConfig Account 18 { 19 get 20 { 21 return AccountConfig.Instance; 22 } 23 } 24 25 26 27 private MarketplaceWebServiceConfig GetConfig() 28 { 29 var config = new MarketplaceWebServiceConfig(); 30 config.ServiceURL = Account.ServiceUrl; 31 return config; 32 } 33 34 private MarketplaceWebServiceClient GetClient() 35 { 36 var config = this.GetConfig(); 37 var client = new MarketplaceWebServiceClient(Account.AccessKeyId, Account.SecretAccessKey, Account.AppName, Account.AppVersion, config); 38 return client; 39 } 40 41 public void GetReportList() 42 { 43 var reportList = GetReportListInfo(); 44 foreach (var item in reportList) 45 { 46 GetReport(item); 47 } 48 49 } 50 51 52 private List<string> GetReportListInfo() 53 { 54 List<string> reportIdList = new List<string>(); 55 var client = GetClient(); 56 var request = new GetReportListRequest(); 57 request.Acknowledged = false; 58 request.Merchant = Account.MerchantId; 59 request.ReportTypeList = new TypeList(); 60 request.ReportTypeList.Type = new List<string>() { ReportType }; 61 request.Marketplace = Account.MarketplaceId; 62 request.AvailableFromDate = new DateTime(2014, 7, 15, 0, 0, 0); 63 request.AvailableToDate = new DateTime(2014, 7, 31, 0, 0, 0); 64 65 var response = client.GetReportList(request); 66 var result = response.GetReportListResult; 67 result.ReportInfo.ForEach(u => reportIdList.Add(u.ReportId)); 68 69 return reportIdList; 70 } 71 72 73 /// <summary> 74 /// 获得请求报告: 未测试 75 /// </summary> 76 /// <param name="client"></param> 77 /// <param name="reportId"></param> 78 /// <returns></returns> 79 public void GetReport(string reportId) 80 { 81 var client = this.GetClient(); 82 var request = new GetReportRequest(); 83 request.Merchant = Account.MerchantId; 84 request.ReportId = reportId; 85 86 string fileName = GetFilePath(); 87 request.Report = File.Open(fileName, FileMode.Create, FileAccess.ReadWrite); 88 GetReportResponse response = client.GetReport(request); 89 request.Report.Close(); 90 var result = response.GetReportResult; 91 if (!result.IsSetContentMD5())