Statuses/public timeline/en

跳转到: 导航, 搜索
(清空页面)
第1行: 第1行:
 +
{{api_desc2|
 +
uri=statuses/public_timeline|
 +
desc=返回最新的20条公共微博。返回结果非完全实时,最长会缓存60秒|
 +
format=XML/JSON|
 +
httpMethod=GET|
 +
needAuth=false|
 +
rateLimit=true|
 +
params={{api_args|count|false|int,缺省值20,最大值200|每次返回的记录数}}
 +
{{api_args|base_app|false|int|是否仅获取当前应用发布的信息。0为所有,1为仅本应用。}}|
 +
getParam=&count=5|
 +
postParam=|
 +
result=
 +
===XML示例===
 +
<pre>
 +
<?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>
 +
</pre>
 +
===JSON示例===
 +
<pre>
 +
[
 +
    {
 +
        "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>"
 +
    },
 +
...
 +
]
 +
</pre>
 +
{{Param_statues}}
 +
{{Param_user}}|
 +
useAge=无|
 +
otherInfo=
 +
====Java示例====
 +
请从 [[SDK | 微博SDK开发包下载]] 下载Java SDK<br>
 +
代码示例如下:
 +
<pre>
 +
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;
 +
}
 +
}
 +
</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>
 +
}}

2011年1月19日 (三) 17:09的版本

目录

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