以user_timeline接口为例
先说一下我的思路
首先你得明白微博接口调用的本质
其实你下载的那个sdk只是又封装了一下,但其核心就是模拟浏览器发送post或者get请求获取json数据,
$res = Http::request($url, $params, 'GET');//访问api
这句话就是来用get方法调用api的
指定日期如2013/7/20
将其转化成int
intval(strtotime("2013/7/20"));
拿出每条微博的created_at将其转化成int在与指定日期比
具体实现如下
public static function getWeiboByDate($access_token,$screen_name, $startDate){
$url="https://api.weibo.com/2/statuses/user_timeline.json";
$page=1;
$count=100;
$continue=true;
$j=0;
$i=0;
while($continue){
$params=array(
"access_token"=> $access_token,
"screen_name"=> $screen_name,
"page"=>$page,
"count"=>$count
);
$res = Http::request($url, $params, 'GET');//访问api
$result = json_decode($res,true);
foreach($result['statuses'] as $key => $value){
// $time[$i]= strtotime($value['created_at']);
if(intval(strtotime($value['created_at']))>$startDate){
$wl[$i]['id']=$value['id'];
$wl[$i]['source']=$value['source'];
$wl[$i]['text']=$value['text'];
if(isset($value['retweeted_status'])){
$wl[$i]['type'] = "转发";
}
else{
$wl[$i]['type'] = "原创";
}
$wl[$i]['reposts_count'] =$value['reposts_count'];
$wl[$i]['comments_count'] =$value['comments_count'];
$wl[$i]['created_at'] =$value['created_at'];
$wl[$i]['bmiddle_pic'] = $value['bmiddle_pic'];
preg_match_all("%#(.*?)#%si",$value['text'],$match);
$wl[$i]['title'] = $match[1][0];
$i++;
}
}
$endDate = intval(strtotime($result['statuses'][$count-1]['created_at']));
if($endDate>$startDate){
$continue=true;
}
else{
$continue = false;
}
$page++;
}
return $wl;
}