PHP用curl获取自己微博的数据
由于公司内部需要一个触摸屏,屏幕上自动滚动一条数据,为了节省重新发布的时间打算用历史新浪微博发布的数据。
第一步:登录新浪微博,得到COOKIE
$cookie='UOR=www.baidu.com,weibo.com,www.baidu.com; SINAGLOBAL=2488257599505.5103.1708346677616; _s_tentry=www.baidu.com; Apache=3029781718790.481.1713013686223; ULV=1713013686225:3:1:1:3029781718790.481.1713013686223:1710420145127; PC_TOKEN=3ca818ce6a; SUBP=0033WrSXqPxfM725Ws9jqgMF55529P9D9W5ANHyGYZ5CysrUYOAzkhid5JpX5KzhUgL.Fo20S0qcehM4SK22dJLoIEXLxK.L1hML1K2LxKMLBKML1h5LxKML1-qLBoeLxK-LBoBL1KqLxKnL12eLBoqt; XSRF-TOKEN=WRgpCaWWBugH5UouG3COa5mp; WBPSESS=Pe-jTpUJVv4hHNFo_fQZxuGPxtdzm0W65mQFb7ToKLzoV6GDznAj7aqaiDRwkEHo4jFrbQg4psYN9rPvPrqvGwDbfF8iIYBD9M7L_NFGZUui2wmLzlm1q3kQzoq1IaxmCYUV6eZGbO0kDx3c7NJq_g==; ALF=1715605876; SUB=_2A25LHvQjDeRhGedN7FQX8CnFzj2IHXVoUgnrrDV8PUJbkNAGLWbHkW1NVfTeCypYKIEwEgeXqCvH7dESSedGEUVQ';
不明白为啥有UOR=www.baidu.com
第二步:找到内容列表的链接
//当前链接下载后,有一个since_id为下一页的访问限定
$url='https://weibo.com/ajax/statuses/mymblog?uid=1376607951&page=5&feature=0&since_id=3912360798329493';
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60000);
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
返回的结果是JSON数组,处理好入库。