以下代码实现了访问实时报告中的关键词报告功能,最大获取数量5000关键词。

<?php 
$arr = array(
"header"=>array("token"=>"",
"username"=>"",
"password"=>""),
"body"=>array ('realTimeRequestTypes'=>array(
"performanceData"=>array("impression","click"),
"startDate"=>"2015-06-16T15:13:00.000",
"endDate"=>"2015-06-16T23:59:59.000",
"levelOfDetails"=>11,
"statRange"=>11,
"unitOfTime"=>8,
"reportType"=>14,
"number"=>5000
)
)
);
$data=json_encode($arr);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://api.baidu.com/json/sms/v3/ReportService/getRealTimeData" );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER,array('Content-Type: application/json; charset=utf-8'));
$result=curl_exec ($ch);
print_r(json_decode($result, true));
die();

方法来源:http://dev2.baidu.com/docs.do?product=1#page=REST%E9%A3%8E%E6%A0%BC%E7%9A%84API

Related Posts: 百度搜索推广API-PHP调用返回json示例 :