Statuses/counts
(→使用示例:) |
(→PHP示例) |
||
第56行: | 第56行: | ||
curl -u uid:password http://api.t.sina.com.cn/statuses/counts.json?ids=1&source=appkey | curl -u uid:password http://api.t.sina.com.cn/statuses/counts.json?ids=1&source=appkey | ||
====PHP示例==== | ====PHP示例==== | ||
+ | 请从 [[SDK | 微博SDK开发包下载]] 处下载PHP SDK(支持OAuth验证之版本)<br> | ||
+ | 代码示例如下: | ||
<pre> | <pre> | ||
//Statuses/counts | //Statuses/counts | ||
− | $c = new WeiboClient( WB_AKEY , WB_SKEY , $_SESSION['last_key']['oauth_token'] , $_SESSION['last_key']['oauth_token_secret'] ); | + | $c = new WeiboClient( WB_AKEY , |
+ | WB_SKEY , | ||
+ | $_SESSION['last_key']['oauth_token'] , | ||
+ | $_SESSION['last_key']['oauth_token_secret'] ); | ||
$u_id = "u_id"; | $u_id = "u_id"; | ||
$msg = $c->user_timeline($u_id); | $msg = $c->user_timeline($u_id); |
2010年8月4日 (三) 15:04的版本
目录 |
statuses/counts
批量统计微博的评论数,转发数,一次请求最多获取100个。
URL:
http://api.t.sina.com.cn/statuses/counts.format
格式:
xml, json
是否需要登录:
GET
请求数限制:
true
请求参数
- ids. 必填参数. 微博ID号列表,用逗号隔开
o 示例: http://api.t.sina.com.cn/statuses/counts.xml?ids=32817222,214672651
使用说明
- 缺少参数返回403
- 不存在的id(或者已删除微博的id)在结果集中会直接忽略,而不会返回其他提示。
返回结果
XML示例:
<?xml version="1.0" encoding="UTF-8"?> <counts> <count> <id>32817222</id> <comments>10</comments> <rt>21</rt > </count> <count> <id>214672651</id> <comments>123</comments> <rt>129</rt > </count> </counts>
JSON示例:
[ {"id":32817222, "comments":0, "rt":0}, {"id":214672651, "comments":0, "rt":0} ]
使用示例:
需修改appkey
- xml:
curl -u uid:password http://api.t.sina.com.cn/statuses/counts.xml?ids=1&source=appkey
- json:
curl -u uid:password http://api.t.sina.com.cn/statuses/counts.json?ids=1&source=appkey
PHP示例
请从 微博SDK开发包下载 处下载PHP SDK(支持OAuth验证之版本)
代码示例如下:
//Statuses/counts $c = new WeiboClient( WB_AKEY , WB_SKEY , $_SESSION['last_key']['oauth_token'] , $_SESSION['last_key']['oauth_token_secret'] ); $u_id = "u_id"; $msg = $c->user_timeline($u_id); if ($msg === false || $msg === null){ echo "Error occured"; return false; } if (isset($msg['error_code']) && isset($msg['error'])){ echo ('Error_code: '.$msg['error_code'].'; Error: '.$msg['error'] ); return false; } if (count($msg)> 1){ $sid1 = $msg[0]['id']; $sid2 = $msg[1]['id']; $sid_total = $sid1.",".$sid2; $msg = $c->get_count_info_by_ids($sid_total); if ($msg === false || $msg === null){ echo "Error occured"; return false; } if (isset($msg['error_code']) && isset($msg['error'])){ echo ('Error_code: '.$msg['error_code'].'; Error: '.$msg['error'] ); return false; } foreach($msg as $data){ $id = $data['id']; $num_comments = $data['comments']; $num_rts = $data['rt']; echo $id."=".$num_comments."&".$num_rts.";"; } }