Statuses/user timeline

跳转到: 导航, 搜索
(使用示例)
 
(未显示6个用户的29个中间版本)
第1行: 第1行:
== statuses/user_timeline ==
+
{{api_desc2|
返回用户的发布的最近n条信息,和用户微博页面返回内容是一致的。此接口也可以请求其他用户的最新发表微博。
+
uri=statuses/user_timeline|
 
+
desc=返回用户最新发表的微博消息列表。|
=== URL===
+
format=XML/JSON|
http://api.t.sina.com.cn/statuses/user_timeline.format
+
httpMethod=GET|
+
needAuth=true|
=== 格式 ===
+
rateLimit=true|
xml, json
+
params={{api_args|:id|false|int64/string|根据用户ID(int64)或者微博昵称(string)返回指定用户的最新微博消息列表。该参数为REST风格参数,参见注意事项}}
+
{{api_args|user_id|false|int64|用户ID,主要是用来区分用户ID跟微博昵称。当微博昵称为数字导致和用户ID产生歧义,特别是当微博昵称和用户ID一样的时候,建议使用该参数}}
=== HTTP请求方式 ===
+
{{api_args|screen_name|false|string|微博昵称,主要是用来区分用户UID跟微博昵称,当二者一样而产生歧义的时候,建议使用该参数}}
GET
+
{{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,最大值200。|指定每页返回的记录条数。}}
true
+
{{api_args|page|false|int,默认值1。|页码。注意:最多返回200条分页内容。}}
 
+
{{api_args_colspan|1=<font style="color:#ee3333">如果:id、user_id、screen_name三个参数均未指定,则返回当前登录用户最近发表的微博消息列表。</font>}}
===请求参数===
+
{{api_args|base_app|false|int|是否基于当前应用来获取数据。1为限制本应用微博,0为不做限制。}}
* id:  可选参数. 根据指定用户UID或微博昵称来返回微博信息。
+
{{api_args|feature|false|int|微博类型,0全部,1原创,2图片,3视频,4音乐. 返回指定类型的微博信息内容。}}|
:o 示例: http://api.t.sina.com.cn/statuses/user_timeline/12345.xml
+
getParam=&user_id=11051|
* user_id:  可选参数.  用户UID,主要是用来区分用户UID跟微博昵称一样,产生歧义的时候,特别是在微博昵称为数字导致和用户Uid发生歧义。
+
postParam=|
:o 示例: http://api.t.sina.com.cn/statuses/user_timeline.xml?user_id=1401881
+
result=
* screen_name:可选参数.微博昵称,主要是用来区分用户UID跟微博昵称一样,产生歧义的时候。
+
===XML示例===
:o 示例: http://api.t.sina.com.cn/statuses/user_timeline.xml?screen_name=101010
+
<pre>
* since_id:可选参数(微博信息ID). 只返回ID比since_id大(比since_id时间晚的)的微博信息内容 
+
<?xml version="1.0" encoding="UTF-8"?>
:o 示例: http://api.t.sina.com.cn/statuses/user_timeline.xml?since_id=12345
+
<statuses>
* max_id: 可选参数(微博信息ID).  返回ID不大于max_id的微博信息内容。
+
:o 示例: Example: http://api.t.sina.com.cn/statuses/user_timeline.xml?max_id=54321
+
* count:  可选参数.  每次返回的最大记录数,最多返回200条,默认20。 
+
:o 示例: http://api.t.sina.com.cn/statuses/user_timeline.xml?count=200
+
* page: 可选参数. 分页返回。注意:最多返回200条分页内容。
+
:o Example: http://api.t.sina.com.cn/statuses/user_timeline.xml?page=3
+
 
+
===使用说明 ===
+
* 默认返回最近15天以内的微博信息
+
* 由于分页限制,暂时最多只能返回用户最新的200条微博信息
+
* 用户最多只能请求到最近200条记录
+
 
+
===返回结果===
+
XML示例:
+
<?xml version="1.0" encoding="UTF-8"?>
+
<statuses>
+
 
   <status>
 
   <status>
     <created_at>Tue Dec 01 08:51:58 +0800 2009</created_at>
+
     <created_at>Mon Nov 29 16:08:43 +0800 2010</created_at>
     <id>99999999</id>
+
     <id>3958728723</id>
     <text>只见AC米兰的巴蒂斯图塔突破马尔蒂尼,一脚凌空抽射,被裁判扑了出来。</text>
+
     <text>各位开发者,我们的论坛上线啦~http://sinaurl.cn/h4FWc7 欢迎大家的参与~另外,关于技术相关的问题,可以在论坛上提出,也可以@微博API 这个官方技术支持账号哦~感谢大家对开放平台的支持~[呵呵]</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>
+
 
     <user>
 
     <user>
       <id>1141457724</id>
+
       <id>11051</id>
       <screen_name>1141457724</screen_name>
+
       <screen_name>微博开放平台</screen_name>
       <name>1141457724</name>
+
       <name>微博开放平台</name>
       <location>广州</location>
+
      <province>11</province>
       <description>blog: timyang.net</description>
+
      <city>8</city>
       <url>http://timyang.net</url>
+
       <location>北京 海淀区</location>
       <profile_image_url>http://portrait.sinaimg.cn/1141457724/50#.jpg</profile_image_url>
+
       <description>新浪微博开放平台市场推广官方账号,如有技术问题,请@微博API或者发私信给微博API</description>
       <followers_count>0</followers_count>
+
       <url>http://open.t.sina.com.cn/</url>
       <friends_count>0</friends_count>
+
       <profile_image_url>http://tp4.sinaimg.cn/11051/50/1280283165/1</profile_image_url>
       <statuses_count>0</statuses_count>
+
      <domain>openapi</domain>
 +
      <gender>m</gender>
 +
       <followers_count>13034</followers_count>
 +
       <friends_count>5</friends_count>
 +
       <statuses_count>157</statuses_count>
 
       <favourites_count>0</favourites_count>
 
       <favourites_count>0</favourites_count>
 +
      <created_at>Wed Jan 20 00:00:00 +0800 2010</created_at>
 
       <following>false</following>
 
       <following>false</following>
 
       <verified>true</verified>
 
       <verified>true</verified>
 +
      <allow_all_act_msg>true</allow_all_act_msg>
 +
      <geo_enabled>true</geo_enabled>
 
     </user>
 
     </user>
    <retweeted_status>
 
      <created_at>Tue Dec 01 08:51:58 +0800 2009</created_at>
 
      <id>100000000</id>
 
      <text>虽然渴者只要少许的水便够了,我却很快活地给与了我全部的水。</text>
 
      <source>
 
        <a href="http://t.sina.com.cn">Web</a>
 
      </source>
 
      <favorited>false</favorited>
 
      <truncated>false</truncated>
 
      <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></in_reply_to_screen_name>
 
      <user>
 
        <id>1337040644</id>
 
        <screen_name>1337040644</screen_name>
 
        <name>1337040644</name>
 
        <location>广州</location>
 
        <description>blog: timyang.net</description>
 
        <profile_image_url>http://portrait.sinaimg.cn/1337040644/50#.jpg</profile_image_url>
 
        <followers_count>0</followers_count>
 
        <friends_count>0</friends_count>
 
        <statuses_count>0</statuses_count>
 
        <favourites_count>0</favourites_count>
 
        <following>false</following>
 
        <verified>false</verified>
 
      </user>
 
    </retweeted_status>
 
 
   </status>
 
   </status>
    ... truncated ...
+
...
</statuses>
+
</statuses>
 
+
</pre>
JSON示例:
+
===JSON示例===
[<br/> {"created_at":"Mon Dec 28 19:20:18 +0800 2009",
+
<pre>
  "id":141654,
+
[
  "text":"aaaasdf",
+
    {
  "source":"<a id=\"0\" href=\"http://t.sina.com.cn/\" rel=\"nofollow\">Web</a>",
+
        "created_at" : "Mon Nov 29 16:08:43 +0800 2010",
  "favorited":false,
+
        "text" : "各位开发者,我们的论坛上线啦~http://sinaurl.cn/h4FWc7 欢迎大家的参与~另外,关于技术相关的问题,可以在论坛上提出,也可以@微博API 这个官方技术支持账号哦~感谢大家对开放平台的支持~[呵呵]",
  "truncated":false,
+
        "truncated" : false,
  "in_reply_to_status_id":"",
+
        "in_reply_to_status_id" : "",
  "in_reply_to_user_id":"",
+
        "in_reply_to_screen_name" : "",
  "in_reply_to_screen_name":"",
+
        "geo" : null,
  "geo":null,
+
        "user" :  
  "user":{"id":11075,
+
        {
        "screen_name":"name_11075",
+
            "name" : "微博开放平台",
        "name":"name_11075",
+
            "domain" : "openapi",
        "province":0,
+
            "geo_enabled" : true,
        "city":0,
+
            "followers_count" : 13034,
        "location":"",
+
            "statuses_count" : 157,
        "description":"",
+
            "favourites_count" : 0,
        "url":"",
+
            "city" : "8",
        "profile_image_url":"http://tp4.sinaimg.cn/11075/50/0",
+
            "description" : "新浪微博开放平台市场推广官方账号,如有技术问题,请@微博API或者发私信给微博API",
        "domain":"11075",
+
            "verified" : true,
        "email":"",
+
            "id" : 11051,
        "qq":"4102",
+
            "gender" : "m",
        "msn":"msn_4102",
+
            "friends_count" : 5,
        "followers_count":28,
+
            "screen_name" : "微博开放平台",
        "friends_count":50,
+
            "allow_all_act_msg" : true,
        "statuses_count":0,
+
            "following" : false,
        "favourites_count":0,
+
            "url" : "http://open.t.sina.com.cn/",
        "created_at":"Thu Jan 01 08:00:00 +0800 1970",
+
            "profile_image_url" : "http://tp4.sinaimg.cn/11051/50/1280283165/1",
        "following":false,
+
            "created_at" : "Wed Jan 20 00:00:00 +0800 2010",
        "geo_enabled":false,
+
            "province" : "11",
        "verified":true}<BR/> },
+
            "location" : "北京 海淀区"
  {},...<br/> ]
+
        },
 
+
        "favorited" : false,
=== 使用示例===
+
        "in_reply_to_user_id" : "",
需修改appkey
+
        "id" : 3958728723,
* xml:
+
        "source" : "<a href=\"http://t.sina.com.cn\" rel=\"nofollow\">新浪微博</a>"
curl  -u uid:password http://api.t.sina.com.cn/statuses/user_timeline.xml?screen_name=timyang?source=appkey
+
    },
 +
...
 +
]
 +
</pre>
 +
{{Param_status}}
 +
{{Param_user}}|
 +
useAge=
 +
* :id为REST风格的参数,使用该参数的URL为:<br/> http://api.t.sina.com.cn/statuses/user_timeline/:id.format <br/> 使用示例如下:<br/> http://api.t.sina.com.cn/statuses/user_timeline/11051.xml?source=appkey<br/>http://api.t.sina.com.cn/statuses/user_timeline/timyang.json?source=appkey
 +
* 默认返回最近15天以内的微博信息
 +
* 由于分页限制,暂时最多只能返回用户最新的200条微博信息
 +
* 用户最多只能请求到最近200条记录|
 +
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 GetUserTimeline {
 +
 +
/**
 +
* 获取用户发布的微博信息列表
 +
* @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 {
 +
//获取24小时内前20条用户的微博信息;args[2]:用户ID
 +
List<Status> statuses = getWeibo(false,args).getUserTimeline(args[2]);
 +
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/user timeline
 +
//获取24小时内前20条用户的微博信息
 +
$c = new WeiboClient( WB_AKEY ,
 +
                      WB_SKEY ,
 +
                      $_SESSION['last_key']['oauth_token'] ,
 +
                      $_SESSION['last_key']['oauth_token_secret']  );
  
* json:
+
//$u_id:用户ID
curl -u uid:password http://api.t.sina.com.cn/statuses/user_timeline.xml?screen_name=timyang?source=appkey
+
$u_id = "用户ID";
 +
$msg  = $c->user_timeline($u_id);
 +
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月17日 (五) 18:11的最后版本

目录

statuses/user_timeline

返回用户最新发表的微博消息列表。

URL

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

支持格式

XML/JSON

HTTP请求方式

GET

是否需要登录

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

请求数限制

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

请求参数

  必选 类型及范围 说明
source true string 申请应用时分配的AppKey,调用接口时候代表应用的唯一身份。(采用OAuth授权方式不需要此参数)
:id false int64/string 根据用户ID(int64)或者微博昵称(string)返回指定用户的最新微博消息列表。该参数为REST风格参数,参见注意事项
user_id false int64 用户ID,主要是用来区分用户ID跟微博昵称。当微博昵称为数字导致和用户ID产生歧义,特别是当微博昵称和用户ID一样的时候,建议使用该参数
screen_name false string 微博昵称,主要是用来区分用户UID跟微博昵称,当二者一样而产生歧义的时候,建议使用该参数
since_id false int64 若指定此参数,则只返回ID比since_id大(即比since_id发表时间晚的)的微博消息。
max_id false int64 若指定此参数,则返回ID小于或等于max_id的微博消息
count false int,默认值20,最大值200。 指定每页返回的记录条数。
page false int,默认值1。 页码。注意:最多返回200条分页内容。
如果:id、user_id、screen_name三个参数均未指定,则返回当前登录用户最近发表的微博消息列表。
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>Mon Nov 29 16:08:43 +0800 2010</created_at>
    <id>3958728723</id>
    <text>各位开发者,我们的论坛上线啦~http://sinaurl.cn/h4FWc7 欢迎大家的参与~另外,关于技术相关的问题,可以在论坛上提出,也可以@微博API 这个官方技术支持账号哦~感谢大家对开放平台的支持~[呵呵]</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>11051</id>
      <screen_name>微博开放平台</screen_name>
      <name>微博开放平台</name>
      <province>11</province>
      <city>8</city>
      <location>北京 海淀区</location>
      <description>新浪微博开放平台市场推广官方账号,如有技术问题,请@微博API或者发私信给微博API</description>
      <url>http://open.t.sina.com.cn/</url>
      <profile_image_url>http://tp4.sinaimg.cn/11051/50/1280283165/1</profile_image_url>
      <domain>openapi</domain>
      <gender>m</gender>
      <followers_count>13034</followers_count>
      <friends_count>5</friends_count>
      <statuses_count>157</statuses_count>
      <favourites_count>0</favourites_count>
      <created_at>Wed Jan 20 00:00:00 +0800 2010</created_at>
      <following>false</following>
      <verified>true</verified>
      <allow_all_act_msg>true</allow_all_act_msg>
      <geo_enabled>true</geo_enabled>
    </user>
  </status>
...
</statuses>

JSON示例

[
    {
        "created_at" : "Mon Nov 29 16:08:43 +0800 2010",
        "text" : "各位开发者,我们的论坛上线啦~http://sinaurl.cn/h4FWc7 欢迎大家的参与~另外,关于技术相关的问题,可以在论坛上提出,也可以@微博API 这个官方技术支持账号哦~感谢大家对开放平台的支持~[呵呵]",
        "truncated" : false,
        "in_reply_to_status_id" : "",
        "in_reply_to_screen_name" : "",
        "geo" : null,
        "user" : 
        {
            "name" : "微博开放平台",
            "domain" : "openapi",
            "geo_enabled" : true,
            "followers_count" : 13034,
            "statuses_count" : 157,
            "favourites_count" : 0,
            "city" : "8",
            "description" : "新浪微博开放平台市场推广官方账号,如有技术问题,请@微博API或者发私信给微博API",
            "verified" : true,
            "id" : 11051,
            "gender" : "m",
            "friends_count" : 5,
            "screen_name" : "微博开放平台",
            "allow_all_act_msg" : true,
            "following" : false,
            "url" : "http://open.t.sina.com.cn/",
            "profile_image_url" : "http://tp4.sinaimg.cn/11051/50/1280283165/1",
            "created_at" : "Wed Jan 20 00:00:00 +0800 2010",
            "province" : "11",
            "location" : "北京 海淀区"
        },
        "favorited" : false,
        "in_reply_to_user_id" : "",
        "id" : 3958728723,
        "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 GetUserTimeline {
 
 	/**
 	 * 获取用户发布的微博信息列表 
 	 * @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 {
 			//获取24小时内前20条用户的微博信息;args[2]:用户ID
 			List<Status> statuses = getWeibo(false,args).getUserTimeline(args[2]);
 			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/user timeline
//获取24小时内前20条用户的微博信息
$c = new WeiboClient( WB_AKEY , 
                      WB_SKEY , 
                      $_SESSION['last_key']['oauth_token'] , 
                      $_SESSION['last_key']['oauth_token_secret']  );

//$u_id:用户ID
$u_id = "用户ID";
$msg  = $c->user_timeline($u_id);
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-17