请选择 进入手机版 | 继续访问电脑版

无忧编程_ASP.NET  / C# / PHP 程序员的软件世界

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 682|回复: 0

百度推广搜索API异步数据报告的下载与保存,另附乱码问题解决方案

[复制链接]

393

主题

424

帖子

1761

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1761
发表于 2018-12-26 10:46:43 | 显示全部楼层 |阅读模式
百度推广搜索API异步数据报告的下载与保存,另附乱码问题解决方案
[C#] 纯文本查看 复制代码
//-------------------------------ReportService------------------------------------------
      ReportService service4 = factory.getService(ReportService.class);
      GetProfessionalReportIdRequest reportIdParamter=new GetProfessionalReportIdRequest();
      ReportRequestType reportType=new ReportRequestType();
      reportType.setReportType(14);
      DateFormat  df=new SimpleDateFormat("yyyy-mm-dd");
      reportType.setStartDate(df.parse("2014-03-05"));
      reportType.setEndDate(df.parse("2014-03-06"));
      reportType.setLevelOfDetails(11);//账户粒度
      reportType.setStatRange(2);
      reportType.setUnitOfTime(4);
      List<String> data=new ArrayList<String>();
      data.add("impression");
      data.add("click");
      data.add("cost");
      data.add("ctr");
      data.add("cpc");
      data.add("cpm");
      data.add("position");
      data.add("conversion");
      reportType.setPerformanceData(data);
      reportIdParamter.setReportRequestType(reportType);
      GetProfessionalReportIdResponse res7=service4.getProfessionalReportId(reportIdParamter);
//       System.out.println(res7);
      GetReportStateRequest  reportState=new GetReportStateRequest();
      reportState.setReportId(res7.getReportId());
      GetReportStateResponse res8=service4.getReportState(reportState);
      GetReportFileUrlResponse res9;
      URL  destUrl;
      long startDate=System.currentTimeMillis();
      System.out.println("startDate:"+startDate);
    for(int i=0;i<1;i++){
  System.out.println(res8.getIsGenerated());
  if(res8.getIsGenerated()==1){
  System.out.println("正在处理中......");
  }
if (res8.getIsGenerated()==3) {
GetReportFileUrlRequest fileUrl=new GetReportFileUrlRequest();
fileUrl.setReportId(res7.getReportId());
res9=service4.getReportFileUrl(fileUrl);
System.out.println(res9.getReportFilePath());
destUrl=new URL(res9.getReportFilePath());
URLConnection httpUrl=destUrl.openConnection();
      httpUrl.connect();
      InputStream content = (InputStream) httpUrl.getContent();
      BufferedReader input=new BufferedReader(new InputStreamReader(content));
      String line;
      FileWriter fw = new FileWriter("D:/project/c.csv");
      PrintWriter pw = new PrintWriter(fw);
      while((line=input.readLine())!=null){
 pw.println(line);
//   System.out.print("账号 ID "+i+":"+input.read()+" ");
//   i++;
      }
      pw.close();
      fw.close();
break;
}
    }
      long endDate=System.currentTimeMillis();
      System.out.println("endDate:"+endDate);
      System.out.println("startDate-endDate:"+(endDate-startDate));

参考资料:http://m.it610.com/article/3138146.htm
参考资料2:http://blog.51cto.com/1723824/1372330
windows .net(C#+MSSQL) linux(php+mysql)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|软件编程 ( 鄂ICP备11006601号鄂公网安备 42011102001337号 |

GMT+8, 2019-1-20 05:38 , Processed in 0.625153 second(s), 24 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表