在Ad Exchange Seller REST API中运行大型报表

时间:2014-12-10 05:45:03

标签: google-plus google-oauth

我有一个要求,我必须在Ad Exchange Seller REST API中运行大型报告。 参考网址https://developers.google.com/ad-exchange/seller-rest/reporting/large_reports。 我按照上面提到的步骤仍然只获得了100,000行,而且响应也不是CSV文件。

        AdExchangeSellerService asv;

        using (var stream = new FileStream(@"client_secrets.json", FileMode.Open, FileAccess.Read))
        {
            GoogleWebAuthorizationBroker.Folder = "Tasks.Auth.Store";
            credential = GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.Load(stream).Secrets, new[] { AdExchangeSellerService.Scope.AdexchangeSeller },
                "abc@gmail.com", CancellationToken.None).Result;

           asv = new AdExchangeSellerService(new AdExchangeSellerService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName = "Test108",
            });


        }

        var startDate = System.DateTime.Now.AddDays(-k).ToString("yyyy-MM-dd");
        var endDate = System.DateTime.Now.AddDays(-k).ToString("yyyy-MM-dd"); 



       var reportRequest = asv.Accounts.Reports.Generate("357435743543565337", startDate, endDate);
        reportRequest.Metric = new List<string> { "AD_REQUESTS", "CLICKS", "MATCHED_AD_REQUESTS_RPM", "EARNINGS", "MATCHED_AD_REQUESTS" };
        reportRequest.Dimension = new List<string> { "DATE", "ADVERTISER_NAME", "AD_TAG_NAME", "COUNTRY_NAME", "PRODUCT_NAME", "TRANSACTION_TYPE_NAME", "BRANDING_TYPE_NAME","AD_UNIT_SIZE_NAME" };


        Google.Apis.Discovery.Parameter param = new Google.Apis.Discovery.Parameter();
        param.Name = "alt";
        param.DefaultValue = "media";
        param.ParameterType = "query";
        param.Pattern = null;
        reportRequest.RequestParameters.Remove("alt");


        reportRequest.RequestParameters.Add("alt", param);
        Google.Apis.AdExchangeSeller.v2_0.Data.Report reportResponse = reportRequest.Execute();

我期待的是响应应该是某些CSV文件的格式,但我得到的是某种表格格式的数据。 我在这里缺少什么?

1 个答案:

答案 0 :(得分:0)

reportRequest.Alt = AdExchangeSellerBaseServiceRequest<Google.Apis.AdExchangeSeller.v2_0.Data.Report>.AltEnum.Csv;
        Stream str = File.Create(csvFilePath);
        reportRequest.Download(str);
        str.Close();
        FileInfo fi = new FileInfo(csvFilePath);
        Decompress(fi);
        DataTable reportResponse = ImportExcel(csvFilePath.Replace("zip","csv"),startDate,endDate);

我终于完成了:)