User/statuses/id/en

Jump to: navigation, search

Contents

 :userid/statuses/:id

Jump to the sigle weibo web address. It can jump to the corresponding web page of the weibo with this URl.

URL

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

Supported Formats

XML/JSON

HTTP Request Method

GET

Requires Authentication

false
See the Authorization Mechanism Statement for authorization details

Requests Count Limitation

false
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)
:userid true int64 Owner’s ID of the Weibo
:id true int64 Weibo ID

Notes

URL Example:http://api.t.sina.com.cn/1773020834/statuses/456?source=appkey

Example Request

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

Response

Jump to the web page of the weibo

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;


public class ForwardStatus {

	/**
	 * 根据微博ID和用户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 {
			List<Status> list = getWeibo(true,args).getUserTimeline();
			if(list.size() > 0) {
			//args[2]:用户的id
			String url = "http://api.t.sina.com.cn/"+args[2]+"/statuses/"+list.get(0).getId();
			//打开单条微博信息页面
			Runtime.getRuntime().exec("cmd /c start "+url);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			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:

//user/statuses/id
$c = new WeiboClient( WB_AKEY , 
                      WB_SKEY , 
                      $_SESSION['last_key']['oauth_token'] , 
                      $_SESSION['last_key']['oauth_token_secret']  );

$msg = $c->user_timeline();
if ($msg === false || $msg === null){
	echo "Error occured";
	return false;
} 
if (count($msg)> 0){
	$uid = 'User ID';
	$sid = $msg[0]['id'];
	$msg  = $c->get_comments_by_sid($sid);
	if ($msg === false || $msg === null){
		echo "Error occured";
		return false;
	}
	$url = "http://api.t.sina.com.cn/".$uid."/statuses/".$sid;
	//To achieve redirection, header() must be called before any actual output is sent, such as HTML tags
	header( 'Location:'.$url );
}



文档更新时间: 20 January 2011