Statuses/counts
(→statuses/counts) |
|||
(未显示2个用户的2个中间版本) | |||
第1行: | 第1行: | ||
− | + | {{api_desc2| | |
− | + | uri=statuses/counts| | |
− | + | desc=批量获取n条微博消息的评论数和转发数。一次请求最多可以获取20条微博消息的评论数和转发数| | |
− | + | format=XML/JSON| | |
− | + | httpMethod=GET| | |
− | + | needAuth=true| | |
− | + | rateLimit=true| | |
− | {{ | + | params={{api_args|ids|true|int64|要获取评论数和转发数的微博消息ID列表,用逗号隔开}}| |
− | + | getParam=&ids=32817222,32817223| | |
− | = | + | postParam=| |
− | + | result= | |
− | + | ===XML示例=== | |
− | + | <pre> | |
− | = | + | <?xml version="1.0" encoding="UTF-8"?> |
− | + | <counts> | |
− | + | ||
− | + | ||
− | === | + | |
− | + | ||
− | + | ||
− | + | ||
<count> | <count> | ||
− | + | <id>32817222</id> | |
− | + | <comments>0</comments> | |
− | + | <rt>0</rt> | |
</count> | </count> | ||
<count> | <count> | ||
− | + | <id>32817223</id> | |
− | + | <comments>3</comments> | |
− | + | <rt>0</rt> | |
</count> | </count> | ||
− | + | </counts> | |
− | + | </pre> | |
− | JSON示例 | + | ===JSON示例=== |
− | + | <pre> | |
− | + | [ | |
− | + | { | |
− | + | "id" : 32817222, | |
− | + | "comments" : 0, | |
− | + | "rt" : 0 | |
− | + | }, | |
− | + | { | |
− | + | "id" : 32817223, | |
− | === | + | "comments" : 3, |
− | + | "rt" : 0 | |
− | + | } | |
− | + | ] | |
− | + | </pre>| | |
− | + | useAge=无| | |
− | + | otherInfo= | |
− | + | ===Java示例=== | |
+ | 请从 [[SDK | 微博SDK开发包下载]] 下载Java SDK<br> | ||
+ | 代码示意如下: | ||
+ | <pre> | ||
+ | |||
+ | public class GetCounts { | ||
+ | |||
+ | /** | ||
+ | * 获取微博消息的评论数和转发数 | ||
+ | * @param args | ||
+ | */ | ||
+ | public static void main(String[] args) { | ||
+ | System.setProperty("weibo4j.oauth.consumerKey", Weibo.CONSUMER_KEY); | ||
+ | System.setProperty("weibo4j.oauth.consumerSecret", Weibo.CONSUMER_SECRET); | ||
+ | try { | ||
+ | Weibo weibo = getWeibo(true,args); | ||
+ | List<Count> counts = weibo.getCounts("32817222"); | ||
+ | for (Count count:counts){ | ||
+ | System.out.println("32817222:"+count.getComments()+" - "+count.getRt()); | ||
+ | } | ||
+ | } catch (Exception e) { | ||
+ | e.printStackTrace(); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | private static Weibo getWeibo(boolean isOauth,String ... args) { | ||
+ | Weibo weibo = new Weibo(); | ||
+ | if(isOauth) {//oauth验证方式 args[0]:访问的token;args[1]:访问的密匙 | ||
+ | weibo.setToken(args[0], args[1]); | ||
+ | }else {//用户登录方式 | ||
+ | weibo.setUserId(args[0]);//用户名/ID | ||
+ | weibo.setPassword(args[1]);//密码 | ||
+ | } | ||
+ | return weibo; | ||
+ | } | ||
+ | } | ||
+ | </pre> | ||
+ | ===PHP示例=== | ||
请从 [[SDK | 微博SDK开发包下载]] 处下载PHP SDK(支持OAuth验证之版本)<br> | 请从 [[SDK | 微博SDK开发包下载]] 处下载PHP SDK(支持OAuth验证之版本)<br> | ||
代码示例如下: | 代码示例如下: | ||
第89行: | 第120行: | ||
} | } | ||
</pre> | </pre> | ||
+ | }} |
2012年9月24日 (一) 11:33的最后版本
目录 |
statuses/counts
批量获取n条微博消息的评论数和转发数。一次请求最多可以获取20条微博消息的评论数和转发数
URL
http://api.t.sina.com.cn/statuses/counts.(json%7Cxml)
支持格式
XML/JSON
HTTP请求方式
GET
是否需要登录
true
关于授权机制,参见授权机制声明
请求数限制
true
关于请求数限制,参见接口访问权限说明
请求参数
必选 | 类型及范围 | 说明 | |
---|---|---|---|
source | true | string | 申请应用时分配的AppKey,调用接口时候代表应用的唯一身份。(采用OAuth授权方式不需要此参数) |
ids | true | int64 | 要获取评论数和转发数的微博消息ID列表,用逗号隔开 |
注意事项
无
返回结果
XML示例
<?xml version="1.0" encoding="UTF-8"?> <counts> <count> <id>32817222</id> <comments>0</comments> <rt>0</rt> </count> <count> <id>32817223</id> <comments>3</comments> <rt>0</rt> </count> </counts>
JSON示例
[ { "id" : 32817222, "comments" : 0, "rt" : 0 }, { "id" : 32817223, "comments" : 3, "rt" : 0 } ]
其他
Java示例
请从 微博SDK开发包下载 下载Java SDK
代码示意如下:
public class GetCounts { /** * 获取微博消息的评论数和转发数 * @param args */ public static void main(String[] args) { System.setProperty("weibo4j.oauth.consumerKey", Weibo.CONSUMER_KEY); System.setProperty("weibo4j.oauth.consumerSecret", Weibo.CONSUMER_SECRET); try { Weibo weibo = getWeibo(true,args); List<Count> counts = weibo.getCounts("32817222"); for (Count count:counts){ System.out.println("32817222:"+count.getComments()+" - "+count.getRt()); } } catch (Exception e) { e.printStackTrace(); } } private static Weibo getWeibo(boolean isOauth,String ... args) { Weibo weibo = new Weibo(); if(isOauth) {//oauth验证方式 args[0]:访问的token;args[1]:访问的密匙 weibo.setToken(args[0], args[1]); }else {//用户登录方式 weibo.setUserId(args[0]);//用户名/ID weibo.setPassword(args[1]);//密码 } return weibo; } }
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.";"; } }
文档更新时间: 2012-09-24