Statuses/public timeline 带应用判断

跳转到: 导航, 搜索
(创建新页面为 '== statuses/public_timeline == 返回最新更新的20条微博消息。为避免资源浪费及提高效率,对消息缓存60秒。 === URL=== http://api.t.sina.com.cn/statu…')
 
 
(未显示2个用户的2个中间版本)
第1行: 第1行:
== statuses/public_timeline ==
+
{{api_desc2|
返回最新更新的20条微博消息。为避免资源浪费及提高效率,对消息缓存60秒。
+
uri=statuses/public_timeline|
 
+
desc=返回最新的20条公共微博。返回结果非完全实时,最长会缓存60秒|
=== URL===
+
format=XML/JSON|
http://api.t.sina.com.cn/statuses/public_timeline.format
+
httpMethod=GET|
+
needAuth=false|
=== 格式===
+
rateLimit=true|
xml, json
+
params={{api_args|count|false|int,缺省值20,最大值200|每次返回的记录数}}
+
{{api_args|base_app|false|int|是否仅获取当前应用发布的信息。0为所有,1为仅本应用。}}|
=== HTTP请求方式===
+
getParam=&count=5|
GET
+
postParam=|
+
result=
=== 是否需要登录===
+
===XML示例===
false
+
<pre>
 
+
<?xml version="1.0" encoding="UTF-8"?>
=== 请求数限制===
+
<statuses>
true
+
  <status>
 
+
     <created_at>Tue Nov 30 14:18:03 +0800 2010</created_at>
=== 请求参数===
+
     <id>3978461363</id>
* base_app: 选填参数,是否基于当前应用来获取数据。
+
     <text>就算把我打的遍体鳞伤也见不得会哭,但是为毛要拿虫子啊!啊?啊!啊?看错你了。人面兽心的家伙。[奥特曼]</text>
+
=== 返回结果 ===
+
XML示例:
+
注意geo地理位置字段仅对有地理位置的微博才有返回
+
<?xml version="1.0" encoding="UTF-8"?>
+
<statuses>
+
<status>
+
     <created_at>Tue Dec 01 08:51:58 +0800 2009</created_at>
+
     <id>99999999</id>
+
     <text>只见AC米兰的巴蒂斯图塔突破马尔蒂尼,一脚凌空抽射,被裁判扑了出来。</text>
+
 
     <source>
 
     <source>
       <a href="http://t.sina.com.cn">Web</a>
+
       <a href="http://t.sina.com.cn">新浪微博</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>1500460450</id>
       <screen_name>1141457724</screen_name>
+
       <screen_name>阿阿阿阿阿_光</screen_name>
       <name>1141457724</name>
+
       <name>阿阿阿阿阿_光</name>
       <location>广州</location>
+
      <province>65</province>
       <description>blog: timyang.net</description>
+
      <city>22</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/jiangwufan</url>
       <friends_count>0</friends_count>
+
       <profile_image_url>http://tp3.sinaimg.cn/1500460450/50/1289923764/0</profile_image_url>
       <statuses_count>0</statuses_count>
+
      <domain>007lawliet</domain>
 +
      <gender>f</gender>
 +
       <followers_count>140</followers_count>
 +
       <friends_count>200</friends_count>
 +
       <statuses_count>475</statuses_count>
 
       <favourites_count>0</favourites_count>
 
       <favourites_count>0</favourites_count>
 +
      <created_at>Fri Jun 25 00:00:00 +0800 2010</created_at>
 
       <following>false</following>
 
       <following>false</following>
       <verified>true</verified>
+
       <verified>false</verified>
 +
      <allow_all_act_msg>false</allow_all_act_msg>
 +
      <geo_enabled>true</geo_enabled>
 
     </user>
 
     </user>
     </status>
+
     <annotations/>
 +
  </status>
 
   ...
 
   ...
  </statuses>
+
</statuses>
JSON示例:
+
</pre>
[ {"created_at":"Wed  Jan  06  11:26:01  +0800 2010",
+
===JSON示例===
  "id":142243,
+
<pre>
  "text":"test  test",
+
[
  "source":"<a  id=\"0\"  href=\"http://t.sina.com.cn/\"  rel=\"nofollow\">Web</a>",
+
    {
  "favorited":false,
+
        "created_at" : "Tue Nov 30 14:34:35 +0800 2010",
  "truncated":false,
+
        "text" : "吃力不讨好的事情我是坚决不会再做了,RI你个仙人!发飙~~~~我只想说档次和素质在那里去了,你也就只能在这种地方混!",
  "in_reply_to_status_id":"",
+
        "truncated" : false,
  "in_reply_to_user_id":"",
+
        "in_reply_to_status_id" : "",
  "in_reply_to_screen_name":"",
+
        "annotations" :  
  "geo":{"type": "Point","coordinates": [23.12 -122.39697]},
+
        [
  "user":{"id":10506,
+
  "screen_name":"name_10506",
+
  "name":"name_10506",
+
  "province":0,
+
  "city":0,
+
  "location":"",
+
  "description":"",
+
  "url":"",
+
  "profile_image_url":"http://tp3.sinaimg.cn/10506/50/0",
+
  "domain":"10506",
+
  "followers_count":24,
+
  "friends_count":50,
+
  "statuses_count":0,
+
  "favourites_count":21,
+
  "created_at":"Thu  Jan  01  08:00:00  +0800  1970",
+
  "following":false,
+
  "geo_enabled":false,
+
  "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
+
  
 +
        ],
 +
        "in_reply_to_screen_name" : "",
 +
        "geo" : null,
 +
        "user" :
 +
        {
 +
            "name" : "习惯寂寞吗",
 +
            "domain" : "",
 +
            "geo_enabled" : true,
 +
            "followers_count" : 5,
 +
            "statuses_count" : 61,
 +
            "favourites_count" : 0,
 +
            "city" : "1",
 +
            "description" : "",
 +
            "verified" : false,
 +
            "id" : 1676792942,
 +
            "gender" : "f",
 +
            "friends_count" : 26,
 +
            "screen_name" : "习惯寂寞吗",
 +
            "allow_all_act_msg" : false,
 +
            "following" : false,
 +
            "url" : "http://1",
 +
            "profile_image_url" : "http://tp3.sinaimg.cn/1676792942/50/1284648784",
 +
            "created_at" : "Wed Dec 30 00:00:00 +0800 2009",
 +
            "province" : "51",
 +
            "location" : "四川 成都"
 +
        },
 +
        "favorited" : false,
 +
        "in_reply_to_user_id" : "",
 +
        "id" : 3978753419,
 +
        "source" : "<a href=\"http://t.sina.com.cn\" rel=\"nofollow\">新浪微博</a>"
 +
    },
 +
...
 +
]
 +
</pre>
 +
{{Param_statues}}
 +
{{Param_user}}|
 +
useAge=无|
 +
otherInfo=
 
====Java示例====
 
====Java示例====
 
请从 [[SDK | 微博SDK开发包下载]] 下载Java SDK<br>
 
请从 [[SDK | 微博SDK开发包下载]] 下载Java SDK<br>
 
代码示例如下:
 
代码示例如下:
 
+
<pre>
 
  package weibo4j.examples;
 
  package weibo4j.examples;
 
   
 
   
第145行: 第147行:
 
  }
 
  }
 
  }
 
  }
 +
</pre>
 +
====PHP示例====
 +
请从 [[SDK | 微博SDK开发包下载]] 处下载PHP SDK(支持OAuth验证之版本)<br>
 +
代码示例如下:
 +
<pre>
 +
//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.";";
 +
}
 +
</pre>
 +
}}

2010年12月13日 (一) 14:03的最后版本

目录

statuses/public_timeline

返回最新的20条公共微博。返回结果非完全实时,最长会缓存60秒

URL

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

支持格式

XML/JSON

HTTP请求方式

GET

是否需要登录

false
关于授权机制,参见授权机制声明

请求数限制

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

请求参数

  必选 类型及范围 说明
source true string 申请应用时分配的AppKey,调用接口时候代表应用的唯一身份。(采用OAuth授权方式不需要此参数)
count false int,缺省值20,最大值200 每次返回的记录数
base_app false int 是否仅获取当前应用发布的信息。0为所有,1为仅本应用。

注意事项

返回结果

XML示例

<?xml version="1.0" encoding="UTF-8"?>
<statuses>
  <status>
    <created_at>Tue Nov 30 14:18:03 +0800 2010</created_at>
    <id>3978461363</id>
    <text>就算把我打的遍体鳞伤也见不得会哭,但是为毛要拿虫子啊!啊?啊!啊?看错你了。人面兽心的家伙。[奥特曼]</text>
    <source>
      <a href="http://t.sina.com.cn">新浪微博</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>1500460450</id>
      <screen_name>阿阿阿阿阿_光</screen_name>
      <name>阿阿阿阿阿_光</name>
      <province>65</province>
      <city>22</city>
      <location>新疆 哈密</location>
      <description>____『 无所事事混吃等死喜欢美少年的夜猫女一只。不怕走夜路但却害怕昆虫的胆小鬼一枚。 』</description>
      <url>http://blog.sina.com.cn/jiangwufan</url>
      <profile_image_url>http://tp3.sinaimg.cn/1500460450/50/1289923764/0</profile_image_url>
      <domain>007lawliet</domain>
      <gender>f</gender>
      <followers_count>140</followers_count>
      <friends_count>200</friends_count>
      <statuses_count>475</statuses_count>
      <favourites_count>0</favourites_count>
      <created_at>Fri Jun 25 00:00:00 +0800 2010</created_at>
      <following>false</following>
      <verified>false</verified>
      <allow_all_act_msg>false</allow_all_act_msg>
      <geo_enabled>true</geo_enabled>
    </user>
    <annotations/>
  </status>
  ...
</statuses>

JSON示例

[
    {
        "created_at" : "Tue Nov 30 14:34:35 +0800 2010",
        "text" : "吃力不讨好的事情我是坚决不会再做了,RI你个仙人!发飙~~~~我只想说档次和素质在那里去了,你也就只能在这种地方混!",
        "truncated" : false,
        "in_reply_to_status_id" : "",
        "annotations" : 
        [

        ],
        "in_reply_to_screen_name" : "",
        "geo" : null,
        "user" : 
        {
            "name" : "习惯寂寞吗",
            "domain" : "",
            "geo_enabled" : true,
            "followers_count" : 5,
            "statuses_count" : 61,
            "favourites_count" : 0,
            "city" : "1",
            "description" : "",
            "verified" : false,
            "id" : 1676792942,
            "gender" : "f",
            "friends_count" : 26,
            "screen_name" : "习惯寂寞吗",
            "allow_all_act_msg" : false,
            "following" : false,
            "url" : "http://1",
            "profile_image_url" : "http://tp3.sinaimg.cn/1676792942/50/1284648784",
            "created_at" : "Wed Dec 30 00:00:00 +0800 2009",
            "province" : "51",
            "location" : "四川 成都"
        },
        "favorited" : false,
        "in_reply_to_user_id" : "",
        "id" : 3978753419,
        "source" : "<a href=\"http://t.sina.com.cn\" rel=\"nofollow\">新浪微博</a>"
    },
...
]

字段说明 - status

  • created_at: 创建时间
  • id: 微博ID
  • text: 微博信息内容
  • source: 微博来源
  • favorited: 是否已收藏
  • truncated: 是否被截断
  • in_reply_to_status_id: 回复ID
  • in_reply_to_user_id: 回复人UID
  • in_reply_to_screen_name: 回复人昵称
  • thumbnail_pic: 缩略图
  • bmiddle_pic: 中型图片
  • original_pic:原始图片
  • user: 作者信息
  • retweeted_status: 转发的博文,内容为status,如果不是转发,则没有此字段

字段说明 - user

  • id: 用户UID
  • screen_name: 微博昵称
  • name: 友好显示名称,同微博昵称
  • province: 省份编码(参考省份编码表)
  • city: 城市编码(参考城市编码表)
  • location:地址
  • description: 个人描述
  • url: 用户博客地址
  • profile_image_url: 自定义图像
  • domain: 用户个性化URL
  • gender: 性别,m--男,f--女,n--未知
  • followers_count: 粉丝数
  • friends_count: 关注数
  • statuses_count: 微博数
  • favourites_count: 收藏数
  • created_at: 创建时间
  • following: 是否已关注(此特性暂不支持)
  • verified: 加V标示,是否微博认证用户

其他

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.";";
}
文档更新时间: 2010-12-13