Statuses/counts

跳转到: 导航, 搜索
(statuses/counts)
第1行: 第1行:
== statuses/counts ==
+
{{api_desc2|
批量统计微博的评论数,转发数,一次请求最多获取100个。
+
uri=statuses/counts|
 
+
desc=批量获取n条微博消息的评论数和转发数。一次请求最多可以获取100条微博消息的评论数和转发数|
{{Api_url|statuses/counts}}
+
format=XML/JSON|
 
+
httpMethod=GET|
{{Api_format|xml, json}}
+
needAuth=true|
+
rateLimit=true|
{{Api_req|GET|true|true}}
+
params={{api_args|ids|true|int64|要获取评论数和转发数的微博消息ID列表,用逗号隔开}}|
 
+
getParam=&ids=32817222,32817223|
===请求参数===
+
postParam=|
* ids.  必填参数.  微博ID号列表,用逗号隔开 
+
result=
o 示例: http://api.t.sina.com.cn/statuses/counts.xml?ids=32817222,214672651
+
===XML示例===
 
+
<pre>
===使用说明===
+
<?xml version="1.0" encoding="UTF-8"?>
* 缺少参数返回403
+
<counts>
* 不存在的id(或者已删除微博的id)在结果集中会直接忽略,而不会返回其他提示。
+
 
+
===返回结果===
+
XML示例:
+
<?xml version="1.0" encoding="UTF-8"?>
+
<counts>
+
 
   <count>
 
   <count>
  <id>32817222</id>
+
    <id>32817222</id>
  <comments>10</comments>
+
    <comments>0</comments>
  <nowiki><rt>21</rt ></nowiki>
+
    <rt>0</rt>
 
   </count>
 
   </count>
 
   <count>
 
   <count>
  <id>214672651</id>
+
    <id>32817223</id>
  <comments>123</comments>
+
    <comments>3</comments>
  <nowiki><rt>129</rt ></nowiki>
+
    <rt>0</rt>
 
   </count>
 
   </count>
</counts>
+
</counts>
 
+
</pre>
JSON示例:
+
===JSON示例===
[
+
<pre>
  {"id":32817222,
+
[
  "comments":0,
+
    {
  "rt":0},
+
        "id" : 32817222,
  {"id":214672651,
+
        "comments" : 0,
  "comments":0,
+
        "rt" : 0
  "rt":0}
+
    },
]
+
    {
 
+
        "id" : 32817223,
===使用示例: ===
+
        "comments" : 3,
需修改appkey
+
        "rt" : 0
* xml:
+
    }
curl -u uid:password http://api.t.sina.com.cn/statuses/counts.xml?ids=1&source=appkey
+
]
 
+
</pre>|
* json:
+
useAge=无|
curl -u uid:password http://api.t.sina.com.cn/statuses/counts.json?ids=1&source=appkey
+
otherInfo=
====PHP示例====
+
===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>
 +
}}

2010年12月1日 (三) 15:11的版本

目录

statuses/counts

批量获取n条微博消息的评论数和转发数。一次请求最多可以获取100条微博消息的评论数和转发数

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.";";
	}
}