Statuses/counts/en

跳转到: 导航, 搜索

目录

statuses/counts

Return the comment count and repost count of a batch of weibos. It has a limitation of 100 weibos for each call.

URL

http://api.t.sina.com.cn/statuses/counts.(json%7Cxml)

Supported Formats

XML/JSON

HTTP Request Method

GET

Requires Authentication

true
See the Authorization Mechanism Statement for authorization details

Requests Count Limitation

true
See the Interface Access Rights Statement for the Request Count Limitaiton details.

Request Parameters

  Requires Type and Range Description
source true string AppKey for the application to identify it. ( This parameter is not needed when using OAuth)
ids true int64 ID list of weibos seprareted by comma.

Notes

None

Example Request

XML
curl -u "username:password" "http://api.t.sina.com.cn/statuses/counts.xml?source=appkey&ids=32817222,32817223"
JSON
curl -u "username:password" "http://api.t.sina.com.cn/statuses/counts.json?source=appkey&ids=32817222,32817223"

Response

XML Example

<?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 Example

[
    {
        "id" : 32817222,
        "comments" : 0,
        "rt" : 0
    },
    {
        "id" : 32817223,
        "comments" : 3,
        "rt" : 0
    }
]

Others

Java Example

Please download Java SDK from . Weibo SDK Development Kit Dowload Site
Sample Code:

 
 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 Example

Please download PHP SDK with OAUTH supported from Weibo SDK Development Kit Dowload Site
. Sample Code:

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