Statuses/show

跳转到: 导航, 搜索
(请求参数)
 
(未显示5个用户的23个中间版本)
第1行: 第1行:
== statuses/show ==
+
{{api_desc2|
获取单条ID的微博信息,作者信息将同时返回。
+
uri=statuses/show/:id|
 
+
desc=根据ID获取单条微博消息,以及该微博消息的作者信息。|
=== URL===
+
format=XML/JSON|
curl http://api.t.sina.com.cn/statuses/show/id.format
+
httpMethod=GET|
 +
needAuth=true|
 +
rateLimit=true|
 +
params={{api_args|:id|true|int64|要获取的微博消息ID,该参数为REST风格的参数}}|
 +
getParam=|
 +
postParam=|
 +
result=
 +
===XML示例===
 +
<pre>
 +
<?xml version="1.0" encoding="UTF-8"?>
 +
<status>
 +
  <created_at>Fri Oct 09 11:32:31 +0800 2009</created_at>
 +
  <id>456</id>
 +
  <text>是这样操作,但是功能表现上还要调整。</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>1773020834</id>
 +
    <screen_name>189_测试2</screen_name>
 +
    <name>189_测试2</name>
 +
    <province>0</province>
 +
    <city>0</city>
 +
    <location/>
 +
    <description/>
 +
    <url/>
 +
    <profile_image_url>http://tp3.sinaimg.cn/1773020834/50/1281023809/1</profile_image_url>
 +
    <domain/>
 +
    <gender>m</gender>
 +
    <followers_count>34</followers_count>
 +
    <friends_count>28</friends_count>
 +
    <statuses_count>338</statuses_count>
 +
    <favourites_count>0</favourites_count>
 +
    <created_at>Thu Jul 29 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>
 +
</pre>
 +
===JSON示例===
 +
<pre>
 +
{
 +
    "created_at" : "Fri Oct 09 11:32:31 +0800 2009",
 +
    "text" : "是这样操作,但是功能表现上还要调整。",
 +
    "truncated" : false,
 +
    "in_reply_to_status_id" : "",
 +
    "in_reply_to_screen_name" : "",
 +
    "geo" : null,
 +
    "user" :
 +
    {
 +
        "name" : "189_测试2",
 +
        "domain" : "",
 +
        "geo_enabled" : true,
 +
        "followers_count" : 34,
 +
        "statuses_count" : 338,
 +
        "favourites_count" : 0,
 +
        "city" : "0",
 +
        "description" : "",
 +
        "verified" : false,
 +
        "id" : 1773020834,
 +
        "gender" : "m",
 +
        "friends_count" : 28,
 +
        "screen_name" : "189_测试2",
 +
        "allow_all_act_msg" : false,
 +
        "following" : false,
 +
        "url" : "",
 +
        "profile_image_url" : "http://tp3.sinaimg.cn/1773020834/50/1281023809/1",
 +
        "created_at" : "Thu Jul 29 00:00:00 +0800 2010",
 +
        "province" : "0",
 +
        "location" : ""
 +
    },
 +
    "favorited" : false,
 +
    "in_reply_to_user_id" : "",
 +
    "id" : 456,
 +
    "source" : "<a href=\"/\" rel=\"nofollow\">微博开放平台接口</a>"
 +
}
 +
</pre>|
 +
useAge=如果:id参数输入一个不存在的微博ID,则返回400错误,提示"40031:Error: target weibo does not exist!"|
 +
otherInfo=
 +
===Java示例===
 +
请从 [[SDK | 微博SDK开发包下载]] 下载Java SDK<br>
 +
代码示例如下:
 +
package weibo4j.examples.statuses;
 
   
 
   
=== 格式===
+
import java.util.List;
xml, json
+
import weibo4j.Paging;
 +
import weibo4j.Status;
 +
import weibo4j.Weibo;
 
   
 
   
=== HTTP请求方式===
+
  public class GetStatus {
GET
+
/**
   
+
* 获取单条ID的微博信息,作者信息将同时返回
=== 是否需要身份验证===
+
* @param args
false, unless the author of the status is protected
+
*/
+
public static void main(String[] args) {
=== 请求数限制===
+
System.setProperty("weibo4j.oauth.consumerKey", Weibo.CONSUMER_KEY);
true
+
    System.setProperty("weibo4j.oauth.consumerSecret", Weibo.CONSUMER_SECRET);
 
+
        try {
=== 请求参数===
+
        Weibo weibo = getWeibo(true,args);
* id. 必须参数,要获取已发表的微博ID 
+
        List<Status> list = weibo.getUserTimeline(args[2], new Paging(1).count(4));
o Example: http://api.t.sina.com.cn/statuses/show/142277(微博ID).xml
+
        if(list.size() > 0) {
 
+
        Status status = weibo.showStatus(list.get(0).getId());
=== 返回 ===
+
            System.out.println( status.getId() + " : "+status.getText());
XML示例:
+
        }
<?xml version="1.0" encoding="UTF-8"?>
+
} catch (Exception e) {
  <status>
+
e.printStackTrace();
    <created_at>Tue Dec 01 08:51:58 +0800 2009</created_at>
+
}
    <id>99999999</id>
+
}
    <text>转发:@1141457724 </text>
+
    <source>
+
private static Weibo getWeibo(boolean isOauth,String ... args) {
      <a href="http://t.sina.com.cn">Web</a>
+
Weibo weibo = new Weibo();
    </source>
+
if(isOauth) {//oauth验证方式 args[0]:访问的token;args[1]:访问的密匙
    <favorited>false</favorited>
+
weibo.setToken(args[0], args[1]);
    <truncated>false</truncated>
+
}else {//用户登录方式
    <in_reply_to_status_id></in_reply_to_status_id>
+
    weibo.setUserId(args[0]);//用户名/ID
    <in_reply_to_user_id></in_reply_to_user_id>
+
weibo.setPassword(args[1]);//密码
    <in_reply_to_screen_name></in_reply_to_screen_name>
+
}
    <user>
+
return weibo;
      <id>1141457724</id>
+
}
      <screen_name>1141457724</screen_name>
+
}
      <name>1141457724</name>
+
===PHP示例===
      <location>广州</location>
+
请从 [[SDK | 微博SDK开发包下载]] 处下载PHP SDK(支持OAuth验证之版本)<br>  
      <description>blog: timyang.net</description>
+
代码示例如下:
      <profile_image_url>http://portrait.sinaimg.cn/1141457724/50#.jpg</profile_image_url>
+
<pre>
      <followers_count>0</followers_count>
+
//Statuses/show
      <friends_count>0</friends_count>
+
//获取单条ID的微博信息,作者信息将同时返回
      <statuses_count>0</statuses_count>
+
$c = new WeiboClient( WB_AKEY ,
      <favourites_count>0</favourites_count>
+
                      WB_SKEY ,
      <following>false</following>
+
                      $_SESSION['last_key']['oauth_token'] ,
    </user>
+
                      $_SESSION['last_key']['oauth_token_secret']  );
    <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>
+
      <thumbnail_pic>http://static16.photo.sina.com.cn/thumbnail/62988d06tcbbc377f7bbf</thumbnail_pic>
+
      <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>
+
        <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>
+
      </user>
+
    </retweeted_status>
+
  </status>
+
  
=== 使用示例===
+
$u_id = "用户ID";
cURL:
+
$msg = $c->user_timeline($u_id);
curl http://api.t.sina.com.cn/statuses/show/1472669360.xml
+
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;
 +
}
 +
if (count($msg)>0){
 +
$t_id = $msg[0]['id'];
 +
$msg = $c->show_status($t_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;
 +
}
 +
if (isset($msg['id']) && isset($msg['text'])){
 +
echo($msg['id'].' : '.$msg['text']);
 +
}
 +
}
 +
</pre>
 +
}}

2012年9月24日 (一) 11:35的最后版本

目录

statuses/show/:id

根据ID获取单条微博消息,以及该微博消息的作者信息。

URL

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

支持格式

XML/JSON

HTTP请求方式

GET

是否需要登录

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

请求数限制

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

请求参数

  必选 类型及范围 说明
source true string 申请应用时分配的AppKey,调用接口时候代表应用的唯一身份。(采用OAuth授权方式不需要此参数)
:id true int64 要获取的微博消息ID,该参数为REST风格的参数

注意事项

如果:id参数输入一个不存在的微博ID,则返回400错误,提示"40031:Error: target weibo does not exist!"

返回结果

XML示例

<?xml version="1.0" encoding="UTF-8"?>
<status>
  <created_at>Fri Oct 09 11:32:31 +0800 2009</created_at>
  <id>456</id>
  <text>是这样操作,但是功能表现上还要调整。</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>1773020834</id>
    <screen_name>189_测试2</screen_name>
    <name>189_测试2</name>
    <province>0</province>
    <city>0</city>
    <location/>
    <description/>
    <url/>
    <profile_image_url>http://tp3.sinaimg.cn/1773020834/50/1281023809/1</profile_image_url>
    <domain/>
    <gender>m</gender>
    <followers_count>34</followers_count>
    <friends_count>28</friends_count>
    <statuses_count>338</statuses_count>
    <favourites_count>0</favourites_count>
    <created_at>Thu Jul 29 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>

JSON示例

{
    "created_at" : "Fri Oct 09 11:32:31 +0800 2009",
    "text" : "是这样操作,但是功能表现上还要调整。",
    "truncated" : false,
    "in_reply_to_status_id" : "",
    "in_reply_to_screen_name" : "",
    "geo" : null,
    "user" : 
    {
        "name" : "189_测试2",
        "domain" : "",
        "geo_enabled" : true,
        "followers_count" : 34,
        "statuses_count" : 338,
        "favourites_count" : 0,
        "city" : "0",
        "description" : "",
        "verified" : false,
        "id" : 1773020834,
        "gender" : "m",
        "friends_count" : 28,
        "screen_name" : "189_测试2",
        "allow_all_act_msg" : false,
        "following" : false,
        "url" : "",
        "profile_image_url" : "http://tp3.sinaimg.cn/1773020834/50/1281023809/1",
        "created_at" : "Thu Jul 29 00:00:00 +0800 2010",
        "province" : "0",
        "location" : ""
    },
    "favorited" : false,
    "in_reply_to_user_id" : "",
    "id" : 456,
    "source" : "<a href=\"/\" rel=\"nofollow\">微博开放平台接口</a>"
}

其他

Java示例

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

package weibo4j.examples.statuses;

import java.util.List;
import weibo4j.Paging;
import weibo4j.Status;
import weibo4j.Weibo;

public class GetStatus {
	/**
	 * 获取单条ID的微博信息,作者信息将同时返回
	 * @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 {
       	Weibo weibo = getWeibo(true,args);
       	List<Status> list = weibo.getUserTimeline(args[2], new Paging(1).count(4));
       	if(list.size() > 0) {
       		Status status = weibo.showStatus(list.get(0).getId());
           	System.out.println( status.getId() + "  : "+status.getText());
       	}
		} catch (Exception 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/show
//获取单条ID的微博信息,作者信息将同时返回
$c = new WeiboClient( WB_AKEY , 
                      WB_SKEY , 
                      $_SESSION['last_key']['oauth_token'] , 
                      $_SESSION['last_key']['oauth_token_secret']  );

$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;
}
if (count($msg)>0){
	$t_id = $msg[0]['id'];
	$msg = $c->show_status($t_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;
	}
	if (isset($msg['id']) && isset($msg['text'])){
		echo($msg['id'].' : '.$msg['text']);
	}
}
文档更新时间: 2012-09-24