Statuses/public timeline/en

跳转到: 导航, 搜索

目录

statuses/public_timeline

Return 20 latest public weibo. The Respons is not strictly realtime, and it is cached for 60 seconds.

URL

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

Supported Formats

XML/JSON

HTTP Request Method

GET

Requires Authentication

false
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)
count false iint, default value 20, max value 200 The returned request count.
base_app false int whether get the data based on current application. 1 is only current application; 0 is no limitation.

Notes

None

Example Request

XML
curl -u "username:password" "http://api.t.sina.com.cn/statuses/public_timeline.xml?source=appkey&count=5"
JSON
curl -u "username:password" "http://api.t.sina.com.cn/statuses/public_timeline.json?source=appkey&count=5"

Response

XML Example

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

[
    {
        "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>"
    },
...
]

Field Description - weibo

  • created_at: Create time
  • id: Weibo ID
  • text: Weibo content
  • source: Weibo source
  • favorited: Whether it is favroited
  • truncated: Whether it is truncated
  • in_reply_to_status_id: The reply’s ID
  • in_reply_to_user_id: UID of the replyer
  • in_reply_to_screen_name: Nickname of replyer
  • thumbnail_pic: Thumbnail picture
  • bmiddle_pic: Medium picture
  • original_pic:Original picture
  • user: User profile
  • retweeted_status: eposted weibo content, the content is the status, This filed is only available for a reposted weibo.

Field Description - user

  • id: User ID
  • screen_name: User’s nickname displayed on the home page
  • name: Friendly displayed name, the same as screen_name
  • province: Province code ( see Province and city code table)
  • city: City code ( see Province and city code table)
  • location:Address
  • description: Personal description
  • url: Url of the user’s blog
  • profile_image_url: Profile image
  • domain: The user’s personalized weibo url
  • gender: Gender, m—male, f- - female, n-- unknown
  • followers_count: Followers count
  • friends_count: Following count
  • statuses_count: Weibo count
  • favourites_count: Favorites count
  • created_at: Created time
  • following: Whether the current user is following the user that posts the weibo (Not supported yet)
  • verified: Whether the user is verified by his real identity, marked with “V”

Others

Java Example

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

 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 Example

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

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