Statuses/counts

跳转到: 导航, 搜索
(创建新页面为 '== statuses/counts == 批量统计微薄的评论数,转发数 === URL: === http://api.t.sina.com.cn/statuses/counts.format ===格式:=== xml, json === 是否需要登录…')
 
 
(未显示5个用户的16个中间版本)
第1行: 第1行:
== statuses/counts ==
+
{{api_desc2|
批量统计微薄的评论数,转发数
+
uri=statuses/counts|
 
+
desc=批量获取n条微博消息的评论数和转发数。一次请求最多可以获取20条微博消息的评论数和转发数|
=== URL: ===
+
format=XML/JSON|
http://api.t.sina.com.cn/statuses/counts.format
+
httpMethod=GET|
+
needAuth=true|
===格式:===
+
rateLimit=true|
xml, json
+
params={{api_args|ids|true|int64|要获取评论数和转发数的微博消息ID列表,用逗号隔开}}|
+
getParam=&ids=32817222,32817223|
=== 是否需要登录: ===
+
postParam=|
GET
+
result=
 
+
===XML示例===
===请求数限制:===
+
<pre>
true, 对用户有限制
+
<?xml version="1.0" encoding="UTF-8"?>
 
+
<counts>
===调用频率限制:===
+
false
+
 
+
=== 请求参数===
+
* ids.  必填参数.  微薄ID号列表,用逗号隔开 
+
o Example: http://api.t.sina.com.cn/statuses/counts.xml?ids=32817222,214672651
+
+
===返回:===
+
XML 格式样例(部分内容删减):
+
<?xml version="1.0" encoding="UTF-8"?>
+
<counts>
+
 
   <count>
 
   <count>
  <id>32817222</id>
+
    <id>32817222</id>
  <comments type="integer">10</comments>
+
    <comments>0</comments>
  <reports type="integer">21</reports >
+
    <rt>0</rt>
 
   </count>
 
   </count>
 
   <count>
 
   <count>
  <id>214672651</id>
+
    <id>32817223</id>
  <comments type="integer">123</comments>
+
    <comments>3</comments>
  <reports type="integer">129</reports >
+
    <rt>0</rt>
 
   </count>
 
   </count>
</counts>
+
</counts>
 
+
</pre>
===使用示例: ===
+
===JSON示例===
curl -u user:password http://api.t.sina.com.cn/statuses/counts.xml
+
<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>
 +
代码示例如下:
 +
<pre>
 +
//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.";";
 +
}
 +
}
 +
</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