User/statuses/id
(创建新页面为 '== uid/statuses/id == 单条微博的Web访问路径。可以通过此url跳转到微博对应的Web网页。 === URL=== curl http://api.t.sina.com.cn/userid/statuses/id ===…') |
(→Java示例) |
||
第71行: | 第71行: | ||
} | } | ||
} | } | ||
+ | ====PHP示例==== | ||
+ | <pre> | ||
+ | //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 ); | ||
+ | } | ||
+ | </pre> |
2010年8月4日 (三) 13:40的版本
目录 |
uid/statuses/id
单条微博的Web访问路径。可以通过此url跳转到微博对应的Web网页。
URL
curl http://api.t.sina.com.cn/userid/statuses/id
HTTP请求方式
GET
是否需要身份验证
true
请求数限制
true
请求参数
- id. 必须参数(微博信息ID),要获取已发表的微博ID,如ID不存在返回空
- userid.必须参数 该微博发布人的uid
o 示例: http://api.t.sina.com.cn/1651129457/statuses/31602594
返回结果
跳转到改微博的web页
使用示例
curl -u uid:password http://api.t.sina.com.cn/1651129457/statuses/31602594
Java示例
请从 微博SDK开发包下载 下载Java SDK
代码示意如下:
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示例
//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 ); }