以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;
}