Trends/statuses

跳转到: 导航, 搜索
(trends/statuses)
(trends/statuses)
第7行: 第7行:
  
 
{{Api_req|GET|false|true}}
 
{{Api_req|GET|false|true}}
   
+
 
 +
===请求参数===
 +
*trend_name: 必选  话题关键词
 
=== 返回结果 ===
 
=== 返回结果 ===
 
XML示例:
 
XML示例:
注意geo地理位置字段仅对有地理位置的微博才有返回
+
<?xml version="1.0" encoding="UTF-8"?>
<pre>
+
<statuses>
<?xml version="1.0" encoding="UTF-8"?>
+
  <status>
<statuses>
+
     <created_at>Tue Nov 02 14:42:32 +0800 2010</created_at>
<status>
+
     <id>3397147109</id>
     <created_at>Tue Dec 01 08:51:58 +0800 2009</created_at>
+
     <text>回复@星月的守护:都学啊,现在上JAVA,WINDOWS程序设计;以前学过C,C++。不过不通,现在成问题了。//@星月的守护:你学什么语言?</text>
     <id>99999999</id>
+
     <text>只见AC米兰的巴蒂斯图塔突破马尔蒂尼,一脚凌空抽射,被裁判扑了出来。</text>
+
 
     <source>
 
     <source>
       <a href="http://t.sina.com.cn">Web</a>
+
       <a href="http://news.sina.com.cn/wap/wbk.html">新浪微博手机版</a>
 
     </source>
 
     </source>
 
     <favorited>false</favorited>
 
     <favorited>false</favorited>
 
     <truncated>false</truncated>
 
     <truncated>false</truncated>
     <in_reply_to_status_id></in_reply_to_status_id>
+
     <geo/>
     <in_reply_to_user_id></in_reply_to_user_id>
+
     <in_reply_to_status_id/>
     <in_reply_to_screen_name></in_reply_to_screen_name>
+
     <in_reply_to_user_id/>
     <thumbnail_pic>http://static16.photo.sina.com.cn/thumbnail/62988d06tcbbc377f7bbf</thumbnail_pic>
+
     <in_reply_to_screen_name/>
    <bmiddle_pic>http://static16.photo.sina.com.cn/bmiddle/62988d06tcbbc377f7bbf</bmiddle_pic>
+
    <original_pic>http://static16.photo.sina.com.cn/orignal/62988d06tcbbc377f7bbf</original_pic>
+
    <geo xmlns:georss="http://www.georss.org/georss">
+
      <georss:point>23.12 -122.39697</georss:point>
+
    </geo>
+
 
     <user>
 
     <user>
       <id>1141457724</id>
+
       <id>1752561793</id>
       <screen_name>1141457724</screen_name>
+
       <screen_name>RuanP</screen_name>
       <name>1141457724</name>
+
       <name>RuanP</name>
       <location>广州</location>
+
      <province>42</province>
       <description>blog: timyang.net</description>
+
      <city>1000</city>
       <url>http://timyang.net</url>
+
       <location>湖北</location>
       <profile_image_url>http://portrait.sinaimg.cn/1141457724/50#.jpg</profile_image_url>
+
       <description>海内存知己,天涯若比邻!</description>
       <followers_count>0</followers_count>
+
       <url>http://blog.sina.com.cn/pianruan</url>
       <friends_count>0</friends_count>
+
       <profile_image_url>http://tp2.sinaimg.cn/1752561793/50/1288011459</profile_image_url>
       <statuses_count>0</statuses_count>
+
      <domain>ruanpian</domain>
 +
      <gender>f</gender>
 +
       <followers_count>10</followers_count>
 +
       <friends_count>9</friends_count>
 +
       <statuses_count>77</statuses_count>
 
       <favourites_count>0</favourites_count>
 
       <favourites_count>0</favourites_count>
 +
      <created_at>Tue Jun 08 00:00:00 +0800 2010</created_at>
 
       <following>false</following>
 
       <following>false</following>
       <verified>true</verified>
+
       <verified>false</verified>
 +
      <allow_all_act_msg>true</allow_all_act_msg>
 +
      <geo_enabled>true</geo_enabled>
 
     </user>
 
     </user>
     </status>
+
     <retweeted_status>
  ...
+
      <created_at>Tue Nov 02 11:17:59 +0800 2010</created_at>
  </statuses>
+
      <id>3393817355</id>
</pre>
+
      <text>计算机语言,令人头疼的问题#</text>
 +
      <source>
 +
        <a href="http://news.sina.com.cn/wap/wbk.html">新浪微博手机版</a>
 +
      </source>
 +
      <favorited>false</favorited>
 +
      <truncated>false</truncated>
 +
      <geo/>
 +
      <in_reply_to_status_id/>
 +
      <in_reply_to_user_id/>
 +
      <in_reply_to_screen_name/>
 +
      <user>
 +
        <id>1752561793</id>
 +
        <screen_name>RuanP</screen_name>
 +
        <name>RuanP</name>
 +
        <province>42</province>
 +
        <city>1000</city>
 +
        <location>湖北</location>
 +
        <description>海内存知己,天涯若比邻!</description>
 +
        <url>http://blog.sina.com.cn/pianruan</url>
 +
        <profile_image_url>http://tp2.sinaimg.cn/1752561793/50/1288011459</profile_image_url>
 +
        <domain>ruanpian</domain>
 +
        <gender>f</gender>
 +
        <followers_count>10</followers_count>
 +
        <friends_count>9</friends_count>
 +
        <statuses_count>76</statuses_count>
 +
        <favourites_count>0</favourites_count>
 +
        <created_at>Tue Jun 08 00:00:00 +0800 2010</created_at>
 +
        <following>false</following>
 +
        <verified>false</verified>
 +
        <allow_all_act_msg>true</allow_all_act_msg>
 +
        <geo_enabled>true</geo_enabled>
 +
      </user>
 +
    </retweeted_status>
 +
  </status>
 +
  ...
 +
<statuses>
 
JSON示例:
 
JSON示例:
<pre>
+
[
[ {"created_at":"Wed  Jan  06  11:26:01  +0800 2010",
+
    {
  "id":142243,
+
        "created_at": "Tue Nov 02 14:42:32 +0800 2010",
  "text":"test  test",
+
        "favorited": false,
  "source":"<a id=\"0\"  href=\"http://t.sina.com.cn/\" rel=\"nofollow\">Web</a>",
+
        "geo": null,
  "favorited":false,
+
        "id": 3397147109,
  "truncated":false,
+
        "in_reply_to_screen_name": "",
  "in_reply_to_status_id":"",
+
        "in_reply_to_status_id": "",
  "in_reply_to_user_id":"",
+
        "in_reply_to_user_id": "",
  "in_reply_to_screen_name":"",
+
        "retweeted_status": {
  "geo":{"type": "Point","coordinates": [23.12 -122.39697]},
+
            "created_at": "Tue Nov 02 11:17:59 +0800 2010",  
  "user":{"id":10506,
+
            "favorited": false,
  "screen_name":"name_10506",
+
            "geo": null,
  "name":"name_10506",
+
            "id": 3393817355,  
  "province":0,
+
            "in_reply_to_screen_name": "",
  "city":0,
+
            "in_reply_to_status_id": "",
  "location":"",
+
            "in_reply_to_user_id": "",  
  "description":"",
+
            "source": "<a href=\"http://news.sina.com.cn/wap/wbk.html\" rel=\"nofollow\">\u65b0\u6d6a\u5fae\u535a\u624b\u673a\u7248</a>",  
  "url":"",
+
            "text": "\u8ba1\u7b97\u673a\u8bed\u8a00\uff0c\u4ee4\u4eba\u5934\u75bc\u7684\u95ee\u9898#",  
  "profile_image_url":"http://tp3.sinaimg.cn/10506/50/0",
+
            "truncated": false,  
  "domain":"10506",
+
            "user": {
  "followers_count":24,
+
                "allow_all_act_msg": true,  
  "friends_count":50,
+
                "city": "1000",  
  "statuses_count":0,
+
                "created_at": "Tue Jun 08 00:00:00 +0800 2010",  
  "favourites_count":21,
+
                "description": "\u6d77\u5185\u5b58\u77e5\u5df1\uff0c\u5929\u6daf\u82e5\u6bd4\u90bb\uff01",
  "created_at":"Thu  Jan  01  08:00:00  +0800  1970",
+
                "domain": "ruanpian",  
  "following":false,
+
                "favourites_count": 0,  
  "geo_enabled":false,
+
                "followers_count": 10,
  "verified":false}
+
                "following": false,  
  },
+
                "friends_count": 9,  
  {},...
+
                "gender": "f",  
  ]
+
                "geo_enabled": true,  
</pre>
+
                "id": 1752561793,  
{{Param_statues}}
+
                "location": "\u6e56\u5317",  
{{Param_user}}
+
                "name": "RuanP",  
 +
                "profile_image_url": "http://tp2.sinaimg.cn/1752561793/50/1288011459",  
 +
                "province": "42",  
 +
                "screen_name": "RuanP",  
 +
                "statuses_count": 76,  
 +
                "url": "http://blog.sina.com.cn/pianruan",  
 +
                "verified": false
 +
            }
 +
        },...
 +
]
 
=== 使用示例===
 
=== 使用示例===
 
需修改appkey
 
需修改appkey

2010年11月2日 (二) 14:44的版本

目录

trends/statuses

返回最新更新的20条微博消息。为避免资源浪费及提高效率,对消息缓存60秒。

URL

http://api.t.sina.com.cn/trends/statuses.format

格式

xml, json

HTTP请求方式

GET

是否需要登录

false

请求数限制

true

关于请求数限制,参见接口访问权限说明

请求参数

  • trend_name: 必选 话题关键词

返回结果

XML示例: <?xml version="1.0" encoding="UTF-8"?> <statuses>

 <status>
   <created_at>Tue Nov 02 14:42:32 +0800 2010</created_at>
   <id>3397147109</id>
   <text>回复@星月的守护:都学啊,现在上JAVA,WINDOWS程序设计;以前学过C,C++。不过不通,现在成问题了。//@星月的守护:你学什么语言?</text>
   <source>
     <a href="http://news.sina.com.cn/wap/wbk.html">新浪微博手机版</a>
   </source>
   <favorited>false</favorited>
   <truncated>false</truncated>
   <geo/>
   <in_reply_to_status_id/>
   <in_reply_to_user_id/>
   <in_reply_to_screen_name/>
   <user>
     <id>1752561793</id>
     <screen_name>RuanP</screen_name>
     <name>RuanP</name>
     <province>42</province>
     <city>1000</city>
     <location>湖北</location>
     <description>海内存知己,天涯若比邻!</description>
     <url>http://blog.sina.com.cn/pianruan</url>
     <profile_image_url>http://tp2.sinaimg.cn/1752561793/50/1288011459</profile_image_url>
     <domain>ruanpian</domain>
     <gender>f</gender>
     <followers_count>10</followers_count>
     <friends_count>9</friends_count>
     <statuses_count>77</statuses_count>
     <favourites_count>0</favourites_count>
     <created_at>Tue Jun 08 00:00:00 +0800 2010</created_at>
     <following>false</following>
     <verified>false</verified>
     <allow_all_act_msg>true</allow_all_act_msg>
     <geo_enabled>true</geo_enabled>
   </user>
   <retweeted_status>
     <created_at>Tue Nov 02 11:17:59 +0800 2010</created_at>
     <id>3393817355</id>
     <text>计算机语言,令人头疼的问题#</text>
     <source>
       <a href="http://news.sina.com.cn/wap/wbk.html">新浪微博手机版</a>
     </source>
     <favorited>false</favorited>
     <truncated>false</truncated>
     <geo/>
     <in_reply_to_status_id/>
     <in_reply_to_user_id/>
     <in_reply_to_screen_name/>
     <user>
       <id>1752561793</id>
       <screen_name>RuanP</screen_name>
       <name>RuanP</name>
       <province>42</province>
       <city>1000</city>
       <location>湖北</location>
       <description>海内存知己,天涯若比邻!</description>
       <url>http://blog.sina.com.cn/pianruan</url>
       <profile_image_url>http://tp2.sinaimg.cn/1752561793/50/1288011459</profile_image_url>
       <domain>ruanpian</domain>
       <gender>f</gender>
       <followers_count>10</followers_count>
       <friends_count>9</friends_count>
       <statuses_count>76</statuses_count>
       <favourites_count>0</favourites_count>
       <created_at>Tue Jun 08 00:00:00 +0800 2010</created_at>
       <following>false</following>
       <verified>false</verified>
       <allow_all_act_msg>true</allow_all_act_msg>
       <geo_enabled>true</geo_enabled>
     </user>
   </retweeted_status>
 </status>
  ...
<statuses>

JSON示例: [

   {
       "created_at": "Tue Nov 02 14:42:32 +0800 2010", 
       "favorited": false, 
       "geo": null, 
       "id": 3397147109, 
       "in_reply_to_screen_name": "", 
       "in_reply_to_status_id": "", 
       "in_reply_to_user_id": "", 
       "retweeted_status": {
           "created_at": "Tue Nov 02 11:17:59 +0800 2010", 
           "favorited": false, 
           "geo": null, 
           "id": 3393817355, 
           "in_reply_to_screen_name": "", 
           "in_reply_to_status_id": "", 
           "in_reply_to_user_id": "", 
           "source": "<a href=\"http://news.sina.com.cn/wap/wbk.html\" rel=\"nofollow\">\u65b0\u6d6a\u5fae\u535a\u624b\u673a\u7248</a>", 
           "text": "\u8ba1\u7b97\u673a\u8bed\u8a00\uff0c\u4ee4\u4eba\u5934\u75bc\u7684\u95ee\u9898#", 
           "truncated": false, 
           "user": {
               "allow_all_act_msg": true, 
               "city": "1000", 
               "created_at": "Tue Jun 08 00:00:00 +0800 2010", 
               "description": "\u6d77\u5185\u5b58\u77e5\u5df1\uff0c\u5929\u6daf\u82e5\u6bd4\u90bb\uff01", 
               "domain": "ruanpian", 
               "favourites_count": 0, 
               "followers_count": 10, 
               "following": false, 
               "friends_count": 9, 
               "gender": "f", 
               "geo_enabled": true, 
               "id": 1752561793, 
               "location": "\u6e56\u5317", 
               "name": "RuanP", 
               "profile_image_url": "http://tp2.sinaimg.cn/1752561793/50/1288011459", 
               "province": "42", 
               "screen_name": "RuanP", 
               "statuses_count": 76, 
               "url": "http://blog.sina.com.cn/pianruan", 
               "verified": false
           }
       },...
]

使用示例

需修改appkey

  • xml:

curl -u uid:password http://api.t.sina.com.cn/statuses/public_timeline.xml?source=appkey

  • json:

curl -u uid:password http://api.t.sina.com.cn/statuses/public_timeline.json?source=appkey

Java示例

请从 微博SDK开发包下载 下载Java SDK
代码示例如下:

package weibo4j.examples;

import java.util.List;
import weibo4j.Status;
import weibo4j.Weibo;
import weibo4j.WeiboException; 

public class GetPublicTimeline {

	/**
	 * 获取最新更新的公共微博消息 
	 * @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 {
	 		//获取前20条最新更新的公共微博消息
			 List<Status> statuses = getWeibo(false,args).getPublicTimeline();
			for (Status status : statuses) {
	            System.out.println(status.getUser().getName() + ":" +
	                               status.getText());
	        }
		} catch (WeiboException 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/public timeline
//获取前20条最新更新的公共微博消息
$c = new WeiboClient( WB_AKEY , 
                      WB_SKEY , 
                      $_SESSION['last_key']['oauth_token'] , 
                      $_SESSION['last_key']['oauth_token_secret']  );

$msg  = $c->public_timeline();
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){
	$user_name = $data['user']['name'];
	$text = $data['text'];
	echo $user_name."=".$text.";";
}