Statuses/friends timeline

跳转到: 导航, 搜索
(Response)
 
(未显示8个用户的55个中间版本)
第1行: 第1行:
== statuses/friends_timeline ==
+
{{api_desc2|
Returns the 20 most recent statuses posted by the authenticating user and that user's friends. This is the equivalent of /timeline/home on the Web.
+
uri=statuses/friends_timeline|
method status | report a bug
+
desc=获取当前登录用户及其所关注用户的最新微博消息。和用户登录 http://t.sina.com.cn 后在“我的首页”中看到的内容相同。<br/>别名statuses/home_timeline|
 +
format=XML/JSON|
 +
httpMethod=GET|
 +
needAuth=true|
 +
rateLimit=true|
 +
params={{api_args|since_id|false|int64|若指定此参数,则只返回ID比since_id大的微博消息(即比since_id发表时间晚的微博消息)。}}
 +
{{api_args|max_id|false|int64|若指定此参数,则返回ID小于或等于max_id的微博消息}}
 +
{{api_args|count|false|int,默认值20,最大值100。|指定要返回的记录条数。}}
 +
{{api_args|page|false|int,默认值1。|指定返回结果的页码。根据当前登录用户所关注的用户数及这些被关注用户发表的微博数,翻页功能最多能查看的总记录数会有所不同,通常最多能查看1000条左右。}}
 +
{{api_args|base_app|false|int|是否基于当前应用来获取数据。1为限制本应用微博,0为不做限制。}}
 +
{{api_args|feature|false|int|微博类型,0全部,1原创,2图片,3视频,4音乐. 返回指定类型的微博信息内容。}}|
 +
getParam=&count=5&page=10|
 +
postParam=|
 +
result=
 +
===XML示例===
 +
<pre>
 +
<?xml version="1.0" encoding="UTF-8"?>
 +
<statuses>
 +
  <status>
 +
    <created_at>Tue Nov 30 15:36:28 +0800 2010</created_at>
 +
    <id>3979831859</id>
 +
    <text>ewvxe</text>
 +
    <source>
 +
      <a href="">微博开放平台接口</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>1854740027</id>
 +
      <screen_name>siegetest</screen_name>
 +
      <name>siegetest</name>
 +
      <province>11</province>
 +
      <city>8</city>
 +
      <location>北京 海淀区</location>
 +
      <description>ABCDE</description>
 +
      <url/>
 +
      <profile_image_url>http://tp4.sinaimg.cn/1854740027/50/0/1</profile_image_url>
 +
      <domain/>
 +
      <gender>m</gender>
 +
      <followers_count>3</followers_count>
 +
      <friends_count>20</friends_count>
 +
      <statuses_count>15</statuses_count>
 +
      <favourites_count>0</favourites_count>
 +
      <created_at>Thu Nov 11 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>
 +
  </status>
 +
...
 +
</statuses>
 +
</pre>
 +
===JSON示例===
 +
<pre>
 +
[
 +
    {
 +
        "created_at" : "Tue Nov 30 16:21:13 +0800 2010",
 +
        "text" : "转发微博。",
 +
        "truncated" : false,
 +
        "retweeted_status" :
 +
        {
 +
            "created_at" : "Tue Nov 30 16:05:41 +0800 2010",
 +
            "text" : "对待事物的出发点、立足点,决定着事物的发展及发展后的结果。这个结果实际也是一种相对而言的成败。世俗间追求这种成败却又调整不好出发点,更是找不到立足点。所以成也好败也好,放下了最好。",
 +
            "truncated" : false,
 +
            "in_reply_to_status_id" : "",
 +
            "annotations" :
 +
            [
 +
 
 +
            ],
 +
            "in_reply_to_screen_name" : "",
 +
            "geo" : null,
 +
            "user" :
 +
            {
 +
                "name" : "归元隆印",
 +
                "domain" : "",
 +
                "geo_enabled" : true,
 +
                "followers_count" : 66710,
 +
                "statuses_count" : 77,
 +
                "favourites_count" : 0,
 +
                "city" : "1",
 +
                "description" : "心存慈悲 身奉善行 出世入世 修己助人 归元禅寺官方网站:http://www.guiyuanchansi.net",
 +
                "verified" : true,
 +
                "id" : 1799833402,
 +
                "gender" : "m",
 +
                "friends_count" : 4,
 +
                "screen_name" : "归元隆印",
 +
                "allow_all_act_msg" : false,
 +
                "following" : false,
 +
                "url" : "http://1",
 +
                "profile_image_url" : "http://tp3.sinaimg.cn/1799833402/50/1283207796",
 +
                "created_at" : "Tue Aug 24 00:00:00 +0800 2010",
 +
                "province" : "42",
 +
                "location" : "湖北 武汉"
 +
            },
 +
            "favorited" : false,
 +
            "in_reply_to_user_id" : "",
 +
            "id" : 3980364843,
 +
            "source" : "<a href=\"http://t.sina.com.cn\" rel=\"nofollow\">新浪微博</a>"
 +
        },
 +
        "in_reply_to_status_id" : "",
 +
        "annotations" :
 +
        [
 +
 
 +
        ],
 +
        "in_reply_to_screen_name" : "",
 +
        "geo" : null,
 +
        "user" :
 +
        {
 +
            "name" : "半拉拖鞋",
 +
            "domain" : "banlatuoxie",
 +
            "geo_enabled" : true,
 +
            "followers_count" : 56,
 +
            "statuses_count" : 333,
 +
            "favourites_count" : 1,
 +
            "city" : "5",
 +
            "description" : "在这里,我只管把话发出去,有没有人理就不管我的事了!",
 +
            "verified" : false,
 +
            "id" : 1799824787,
 +
            "gender" : "m",
 +
            "friends_count" : 76,
 +
            "screen_name" : "半拉拖鞋",
 +
            "allow_all_act_msg" : false,
 +
            "following" : false,
 +
            "url" : "http://blog.sina.com.cn/lingdianjingq",
 +
            "profile_image_url" : "http://tp4.sinaimg.cn/1799824787/50/1289443070/1",
 +
            "created_at" : "Sun Sep 05 00:00:00 +0800 2010",
 +
            "province" : "11",
 +
            "location" : "北京 朝阳区"
 +
        },
 +
        "favorited" : false,
 +
        "in_reply_to_user_id" : "",
 +
        "id" : 3980654229,
 +
        "source" : "<a href=\"http://t.sina.com.cn\" rel=\"nofollow\">新浪微博</a>"
 +
    },
 +
...
 +
]
 +
</pre>|
 +
useAge=无|
 +
otherInfo=
 +
===Java示例===
 +
请从 [[SDK | 微博SDK开发包下载]] 下载Java SDK<br>
 +
代码示意如下:
 +
<pre>
 +
package weibo4j.examples;
 
   
 
   
===URL:===
+
import java.util.List;
http://api.t.sina.com.cn/statuses/friends_timeline.format
+
 
   
 
   
===Formats: ===
+
import weibo4j.Status;
xml, json, rss, atom
+
import weibo4j.Weibo;
 +
import weibo4j.WeiboException;
 
   
 
   
===HTTP Method(s):===
+
public class GetFriendsTimeline {
GET
+
/**
+
* 获取当前用户所关注用户的最新微博信息 (别名: statuses/home_timeline)  
===Requires Authentication (about authentication):===
+
* @param args
true
+
*/
+
public static void main(String[] args) {
===API rate limited (about rate limiting):===
+
System.setProperty("weibo4j.oauth.consumerKey", Weibo.CONSUMER_KEY);
1 call per request
+
System.setProperty("weibo4j.oauth.consumerSecret", Weibo.CONSUMER_SECRET);
+
===Parameters:===
+
try {
* since_id. Optional. Returns only statuses with an ID greater than (that is, more recent than) the specified ID.
+
//获取前20条关注用户的微博信息
o Example: http://api.t.sina.com.cn/statuses/friends_timeline.xml?since_id=12345
+
List<Status> statuses = getWeibo(true,args).getFriendsTimeline();
* max_id. Optional.  Returns only statuses with an ID less than (that is, older than) or equal to the specified ID.
+
for (Status status : statuses) {
o Example: http://api.t.sina.com.cn/statuses/friends_timeline.xml?max_id=54321
+
            System.out.println(status.getUser().getName() + ":" +
* count. Optional. Specifies the number of statuses to retrieve. May not be greater than 200.  
+
                              status.getText());
o Example: http://api.t.sina.com.cn/statuses/friends_timeline.xml?count=5
+
        }
* page. Optional. Specifies the page of results to retrieve. Note: there are pagination limits.
+
} catch (WeiboException e) {
o Example: http://api.t.sina.com.cn/statuses/friends_timeline.rss?page=3
+
e.printStackTrace();
 
+
}
===Response ===
+
}
(about return values): XML example (truncated):
+
<?xml version="1.0" encoding="UTF-8"?>
+
private static Weibo getWeibo(boolean isOauth,String[] args) {
<statuses>
+
Weibo weibo = new Weibo();
      <status>
+
if(isOauth) {//oauth验证方式 args[0]:访问的token;args[1]:访问的密匙
<created_at>Tue Apr 07 22:52:51 +0000 2009</created_at>
+
weibo.setToken(args[0], args[1]);
<id>1472669360</id>
+
}else {//用户登录方式
<text>At least I can get your humor through tweets. RT @abdur: I don't mean this in a bad way, but genetically speaking your a cul-de-sac.</text>
+
weibo.setUserId(args[0]);//用户名/ID
<source><a href="http://www.tweetdeck.com/">TweetDeck</a></source>
+
    weibo.setPassword(args[1]);//密码
<truncated>false</truncated>
+
}
<in_reply_to_status_id></in_reply_to_status_id>
+
return weibo;
<in_reply_to_user_id></in_reply_to_user_id>
+
}
<favorited>false</favorited>
+
}
<in_reply_to_screen_name></in_reply_to_screen_name>
+
</pre>
<user>
+
===PHP示例===
<id>1401881</id>
+
请从 [[SDK | 微博SDK开发包下载]] 处下载PHP SDK(支持OAuth验证之版本)<br>  
  <name>Doug Williams</name>
+
代码示例如下:
  <screen_name>dougw</screen_name>
+
<pre>
  <location>San Francisco, CA</location>
+
//Statuses/friends timeline
  <description>Twitter API Support. Internet, greed, users, dougw and opportunities are my passions.</description>
+
//获取前20条最新更新的公共微博消息
  <profile_image_url>http://s3.amazonaws.com/twitter_production/profile_images/59648642/avatar_normal.png</profile_image_url>
+
$c = new WeiboClient( WB_AKEY ,
  <url>http://www.igudo.com</url>
+
                      WB_SKEY ,
  <protected>false</protected>
+
                      $_SESSION['last_key']['oauth_token'] ,
  <followers_count>1027</followers_count>
+
                      $_SESSION['last_key']['oauth_token_secret'] );
  <profile_background_color>9ae4e8</profile_background_color>
+
  <profile_text_color>000000</profile_text_color>
+
  <profile_link_color>0000ff</profile_link_color>
+
  <profile_sidebar_fill_color>e0ff92</profile_sidebar_fill_color>
+
  <profile_sidebar_border_color>87bc44</profile_sidebar_border_color>
+
  <friends_count>293</friends_count>
+
  <created_at>Sun Mar 18 06:42:26 +0000 2007</created_at>
+
  <favourites_count>0</favourites_count>
+
  <utc_offset>-18000</utc_offset>
+
  <time_zone>Eastern Time (US & Canada)</time_zone>
+
  <profile_background_image_url>http://s3.amazonaws.com/twitter_production/profile_background_images/2752608/twitter_bg_grass.jpg</profile_background_image_url>
+
  <profile_background_tile>false</profile_background_tile>
+
  <statuses_count>3390</statuses_count>
+
  <notifications>false</notifications>
+
  <following>false</following>
+
  <verified>true</verified>
+
  </user>
+
<geo/>
+
      </status>
+
      ... truncated ...
+
</statuses>
+
 
+
===Usage examples: ===
+
cURL (about cURL):
+
  
curl -u user:password http://api.t.sina.com.cn/statuses/friends_timeline.xml
+
$msg  = $c->friends_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>
 +
}}

2012年2月20日 (一) 18:25的最后版本

目录

statuses/friends_timeline

获取当前登录用户及其所关注用户的最新微博消息。和用户登录 http://t.sina.com.cn 后在“我的首页”中看到的内容相同。
别名statuses/home_timeline

URL

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

支持格式

XML/JSON

HTTP请求方式

GET

是否需要登录

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

请求数限制

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

请求参数

  必选 类型及范围 说明
source true string 申请应用时分配的AppKey,调用接口时候代表应用的唯一身份。(采用OAuth授权方式不需要此参数)
since_id false int64 若指定此参数,则只返回ID比since_id大的微博消息(即比since_id发表时间晚的微博消息)。
max_id false int64 若指定此参数,则返回ID小于或等于max_id的微博消息
count false int,默认值20,最大值100。 指定要返回的记录条数。
page false int,默认值1。 指定返回结果的页码。根据当前登录用户所关注的用户数及这些被关注用户发表的微博数,翻页功能最多能查看的总记录数会有所不同,通常最多能查看1000条左右。
base_app false int 是否基于当前应用来获取数据。1为限制本应用微博,0为不做限制。
feature false int 微博类型,0全部,1原创,2图片,3视频,4音乐. 返回指定类型的微博信息内容。

注意事项

返回结果

XML示例

<?xml version="1.0" encoding="UTF-8"?>
<statuses>
  <status>
    <created_at>Tue Nov 30 15:36:28 +0800 2010</created_at>
    <id>3979831859</id>
    <text>ewvxe</text>
    <source>
      <a href="">微博开放平台接口</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>1854740027</id>
      <screen_name>siegetest</screen_name>
      <name>siegetest</name>
      <province>11</province>
      <city>8</city>
      <location>北京 海淀区</location>
      <description>ABCDE</description>
      <url/>
      <profile_image_url>http://tp4.sinaimg.cn/1854740027/50/0/1</profile_image_url>
      <domain/>
      <gender>m</gender>
      <followers_count>3</followers_count>
      <friends_count>20</friends_count>
      <statuses_count>15</statuses_count>
      <favourites_count>0</favourites_count>
      <created_at>Thu Nov 11 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>
  </status>
...
</statuses>

JSON示例

[
    {
        "created_at" : "Tue Nov 30 16:21:13 +0800 2010",
        "text" : "转发微博。",
        "truncated" : false,
        "retweeted_status" : 
        {
            "created_at" : "Tue Nov 30 16:05:41 +0800 2010",
            "text" : "对待事物的出发点、立足点,决定着事物的发展及发展后的结果。这个结果实际也是一种相对而言的成败。世俗间追求这种成败却又调整不好出发点,更是找不到立足点。所以成也好败也好,放下了最好。",
            "truncated" : false,
            "in_reply_to_status_id" : "",
            "annotations" : 
            [

            ],
            "in_reply_to_screen_name" : "",
            "geo" : null,
            "user" : 
            {
                "name" : "归元隆印",
                "domain" : "",
                "geo_enabled" : true,
                "followers_count" : 66710,
                "statuses_count" : 77,
                "favourites_count" : 0,
                "city" : "1",
                "description" : "心存慈悲 身奉善行 出世入世 修己助人 归元禅寺官方网站:http://www.guiyuanchansi.net",
                "verified" : true,
                "id" : 1799833402,
                "gender" : "m",
                "friends_count" : 4,
                "screen_name" : "归元隆印",
                "allow_all_act_msg" : false,
                "following" : false,
                "url" : "http://1",
                "profile_image_url" : "http://tp3.sinaimg.cn/1799833402/50/1283207796",
                "created_at" : "Tue Aug 24 00:00:00 +0800 2010",
                "province" : "42",
                "location" : "湖北 武汉"
            },
            "favorited" : false,
            "in_reply_to_user_id" : "",
            "id" : 3980364843,
            "source" : "<a href=\"http://t.sina.com.cn\" rel=\"nofollow\">新浪微博</a>"
        },
        "in_reply_to_status_id" : "",
        "annotations" : 
        [

        ],
        "in_reply_to_screen_name" : "",
        "geo" : null,
        "user" : 
        {
            "name" : "半拉拖鞋",
            "domain" : "banlatuoxie",
            "geo_enabled" : true,
            "followers_count" : 56,
            "statuses_count" : 333,
            "favourites_count" : 1,
            "city" : "5",
            "description" : "在这里,我只管把话发出去,有没有人理就不管我的事了!",
            "verified" : false,
            "id" : 1799824787,
            "gender" : "m",
            "friends_count" : 76,
            "screen_name" : "半拉拖鞋",
            "allow_all_act_msg" : false,
            "following" : false,
            "url" : "http://blog.sina.com.cn/lingdianjingq",
            "profile_image_url" : "http://tp4.sinaimg.cn/1799824787/50/1289443070/1",
            "created_at" : "Sun Sep 05 00:00:00 +0800 2010",
            "province" : "11",
            "location" : "北京 朝阳区"
        },
        "favorited" : false,
        "in_reply_to_user_id" : "",
        "id" : 3980654229,
        "source" : "<a href=\"http://t.sina.com.cn\" rel=\"nofollow\">新浪微博</a>"
    },
...
]

其他

Java示例

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

 package weibo4j.examples;
 
 import java.util.List;
 
 import weibo4j.Status;
 import weibo4j.Weibo;
 import weibo4j.WeiboException;
 
 public class GetFriendsTimeline {
 	/**
 	 * 获取当前用户所关注用户的最新微博信息 (别名: statuses/home_timeline) 
 	 * @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(true,args).getFriendsTimeline();
 			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/friends timeline
//获取前20条最新更新的公共微博消息
$c = new WeiboClient( WB_AKEY , 
                      WB_SKEY , 
                      $_SESSION['last_key']['oauth_token'] , 
                      $_SESSION['last_key']['oauth_token_secret']  );

$msg  = $c->friends_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.";";
}
文档更新时间: 2012-02-20