Favorites

跳转到: 导航, 搜索
(PHP示例)
第1行: 第1行:
== favorites ==
+
{{api_desc2|
返回用户的发布的最近20条收藏信息,和用户收藏页面返回内容是一致的。
+
uri=favorites|
 
+
desc=返回用户的发布的最近20条收藏信息,和用户收藏页面返回内容是一致的。|
=== URL===
+
format=XML/JSON|
http://api.t.sina.com.cn/favorites.format
+
httpMethod=GET|
+
needAuth=true|
=== 格式===
+
rateLimit=true|
xml, json
+
params={{api_args|page|false|int|页码。}}|
+
getParam=&page=2|
=== HTTP请求方式===
+
postParam=|
GET
+
result=
+
===XML示例===
=== 是否需要登录===
+
<pre>
true
+
<?xml version="1.0" encoding="UTF-8"?>
 
+
<statuses>
=== 请求数限制===
+
true
+
 
+
===请求参数===
+
* page: 可选参数. 返回结果的页序号。注意:有分页限制。
+
o 示例: http://api.t.sina.com.cn/favorites.xml?page=3
+
 
+
=== 返回结果===
+
XML示例:
+
<?xml version="1.0" encoding="UTF-8"?>
+
<statuses>
+
 
   <status>
 
   <status>
  <id>8374590856</id>
+
    <created_at>Thu Mar 18 19:07:05 +0800 2010</created_at>
  <text>微博平台很重要的一点在于多渠道,使得用户可以随时随地随意收发信息,我们会在这个 方向努力的。</text>
+
    <id>1</id>
  <source>
+
    <text>这么小就入党了 敬仰~</text>
    <a href="http://t.sina.com.cn">Web</a>
+
    <source>
  </source>
+
      <a href="http://news.sina.com.cn/wap/wbk.html/">新浪微博手机版</a>
  <favorited>false</favorited>
+
    </source>
  <truncated>false</truncated>
+
    <favorited>true</favorited>
  <created_at>Tue Nov 17 20:11:24 +0800 2009</created_at>
+
    <truncated>false</truncated>
  <user>
+
    <geo/>
    <id>10503</id>
+
    <in_reply_to_status_id/>
    <screen_name>timyang</screen_name>
+
    <in_reply_to_user_id/>
    <name>Tim Yang</name>
+
    <in_reply_to_screen_name/>
    <location>广州</location>
+
    <user>
    <description>blog: timyang.net</description>
+
      <id>1152759471</id>
    <url></url>
+
      <screen_name>老王</screen_name>
    <profile_image_url>http://tt8.sinaimg.cn/10503/50/1256306049</profile_image_url>
+
      <name>老王</name>
    <followers_count>0</followers_count>
+
      <province>11</province>
    <friends_count>0</friends_count>
+
      <city>8</city>
    <statuses_count>0</statuses_count>
+
      <location>北京 海淀区</location>
    <favourites_count>0</favourites_count>
+
      <description>哼。。。 花样真多。 讨厌。</description>
  </user>
+
      <url>http://1</url>
</status>
+
      <profile_image_url>http://tp4.sinaimg.cn/1152759471/50/1263371934</profile_image_url>
   ... truncated ...
+
      <domain>hotpixel</domain>
</statuses>
+
      <gender>m</gender>
 
+
      <followers_count>1567</followers_count>
=== 使用示例===
+
      <friends_count>202</friends_count>
* xml:
+
      <statuses_count>6776</statuses_count>
curl -u "uid:password" http://api.t.sina.com.cn/favorites.xml
+
      <favourites_count>0</favourites_count>
* json:
+
      <created_at>Fri Aug 28 00:00:00 +0800 2009</created_at>
curl -u "uid:password" http://api.t.sina.com.cn/favorites.json
+
      <following>false</following>
 
+
      <verified>false</verified>
====Java示例====
+
      <allow_all_act_msg>false</allow_all_act_msg>
 +
      <geo_enabled>false</geo_enabled>
 +
    </user>
 +
    <retweeted_status>
 +
      <created_at>Thu Mar 18 19:05:52 +0800 2010</created_at>
 +
      <id>27657268</id>
 +
      <text>班里开始交团费了,跟我没关系</text>
 +
      <source>
 +
        <a href="http://news.sina.com.cn/wap/wbk.html/">新浪微博手机版</a>
 +
      </source>
 +
      <favorited>true</favorited>
 +
      <truncated>false</truncated>
 +
      <geo/>
 +
      <in_reply_to_status_id/>
 +
      <in_reply_to_user_id/>
 +
      <in_reply_to_screen_name/>
 +
      <user>
 +
        <id>1654703984</id>
 +
        <screen_name>高考铅笔亚克西</screen_name>
 +
        <name>高考铅笔亚克西</name>
 +
        <province>42</province>
 +
        <city>1</city>
 +
        <location>湖北 武汉</location>
 +
        <description>在通往高考的路上乳摇狂奔,偶尔发骚回头抛个媚眼骂句操蛋,切不可以为姐就是招之即上挥之自摸的小娘儿们。好不容易成年了,姐要更加有湿想嗯哼。</description>
 +
        <url/>
 +
        <profile_image_url>http://tp1.sinaimg.cn/1654703984/50/1264140632</profile_image_url>
 +
        <domain>kimmy14</domain>
 +
        <gender>f</gender>
 +
        <followers_count>1330</followers_count>
 +
        <friends_count>755</friends_count>
 +
        <statuses_count>3354</statuses_count>
 +
        <favourites_count>0</favourites_count>
 +
        <created_at>Mon Oct 19 00:00:00 +0800 2009</created_at>
 +
        <following>false</following>
 +
        <verified>false</verified>
 +
        <allow_all_act_msg>false</allow_all_act_msg>
 +
        <geo_enabled>false</geo_enabled>
 +
      </user>
 +
    </retweeted_status>
 +
  </status>
 +
   ...
 +
</statuses>
 +
</pre>
 +
===JSON示例===
 +
<pre>
 +
[
 +
    {
 +
        "created_at" : "Thu Mar 18 19:07:05 +0800 2010",
 +
        "text" : "这么小就入党了 敬仰~",
 +
        "truncated" : false,
 +
        "retweeted_status" :
 +
        {
 +
            "created_at" : "Thu Mar 18 19:05:52 +0800 2010",
 +
            "text" : "班里开始交团费了,跟我没关系",
 +
            "truncated" : false,
 +
            "in_reply_to_status_id" : "",
 +
            "in_reply_to_screen_name" : "",
 +
            "geo" : null,
 +
            "user" :
 +
            {
 +
                "name" : "高考铅笔亚克西",
 +
                "domain" : "kimmy14",
 +
                "geo_enabled" : false,
 +
                "followers_count" : 1330,
 +
                "statuses_count" : 3354,
 +
                "favourites_count" : 0,
 +
                "city" : "1",
 +
                "description" : "在通往高考的路上乳摇狂奔,偶尔发骚回头抛个媚眼骂句操蛋,切不可以为姐就是招之即上挥之自摸的小娘儿们。好不容易成年了,姐要更加有湿想嗯哼。",
 +
                "verified" : false,
 +
                "id" : 1654703984,
 +
                "gender" : "f",
 +
                "friends_count" : 755,
 +
                "screen_name" : "高考铅笔亚克西",
 +
                "allow_all_act_msg" : false,
 +
                "following" : false,
 +
                "url" : "",
 +
                "profile_image_url" : "http://tp1.sinaimg.cn/1654703984/50/1264140632",
 +
                "created_at" : "Mon Oct 19 00:00:00 +0800 2009",
 +
                "province" : "42",
 +
                "location" : "湖北 武汉"
 +
            },
 +
            "favorited" : true,
 +
            "in_reply_to_user_id" : "",
 +
            "id" : 27657268,
 +
            "source" : "<a href=\"http://news.sina.com.cn/wap/wbk.html/\" rel=\"nofollow\">新浪微博手机版</a>"
 +
        },
 +
        "in_reply_to_status_id" : "",
 +
        "in_reply_to_screen_name" : "",
 +
        "geo" : null,
 +
        "user" :
 +
        {
 +
            "name" : "老王",
 +
            "domain" : "hotpixel",
 +
            "geo_enabled" : false,
 +
            "followers_count" : 1567,
 +
            "statuses_count" : 6776,
 +
            "favourites_count" : 0,
 +
            "city" : "8",
 +
            "description" : "哼。。。 花样真多。 讨厌。",
 +
            "verified" : false,
 +
            "id" : 1152759471,
 +
            "gender" : "m",
 +
            "friends_count" : 202,
 +
            "screen_name" : "老王",
 +
            "allow_all_act_msg" : false,
 +
            "following" : false,
 +
            "url" : "http://1",
 +
            "profile_image_url" : "http://tp4.sinaimg.cn/1152759471/50/1263371934",
 +
            "created_at" : "Fri Aug 28 00:00:00 +0800 2009",
 +
            "province" : "11",
 +
            "location" : "北京 海淀区"
 +
        },
 +
        "favorited" : true,
 +
        "in_reply_to_user_id" : "",
 +
        "id" : 1,
 +
        "source" : "<a href=\"http://news.sina.com.cn/wap/wbk.html/\" rel=\"nofollow\">新浪微博手机版</a>"
 +
    },
 +
    ...
 +
]
 +
</pre>|
 +
useAge=无|
 +
otherInfo=
 +
===Java示例===
 
请从 [[SDK | 微博SDK开发包下载]] 下载Java SDK<br>
 
请从 [[SDK | 微博SDK开发包下载]] 下载Java SDK<br>
 
代码示例如下:
 
代码示例如下:
第97行: 第208行:
 
  }
 
  }
 
  }
 
  }
====PHP示例====
+
===PHP示例===
 
请从 [[SDK | 微博SDK开发包下载]] 处下载PHP SDK(支持OAuth验证之版本)<br>  
 
请从 [[SDK | 微博SDK开发包下载]] 处下载PHP SDK(支持OAuth验证之版本)<br>  
 
代码示例如下:
 
代码示例如下:
第122行: 第233行:
 
}
 
}
 
</pre>
 
</pre>
 +
}}

2010年12月8日 (三) 11:04的版本

目录

favorites

返回用户的发布的最近20条收藏信息,和用户收藏页面返回内容是一致的。

URL

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

支持格式

XML/JSON

HTTP请求方式

GET

是否需要登录

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

请求数限制

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

请求参数

  必选 类型及范围 说明
source true string 申请应用时分配的AppKey,调用接口时候代表应用的唯一身份。(采用OAuth授权方式不需要此参数)
page false int 页码。

注意事项

返回结果

XML示例

<?xml version="1.0" encoding="UTF-8"?>
<statuses>
  <status>
    <created_at>Thu Mar 18 19:07:05 +0800 2010</created_at>
    <id>1</id>
    <text>这么小就入党了 敬仰~</text>
    <source>
      <a href="http://news.sina.com.cn/wap/wbk.html/">新浪微博手机版</a>
    </source>
    <favorited>true</favorited>
    <truncated>false</truncated>
    <geo/>
    <in_reply_to_status_id/>
    <in_reply_to_user_id/>
    <in_reply_to_screen_name/>
    <user>
      <id>1152759471</id>
      <screen_name>老王</screen_name>
      <name>老王</name>
      <province>11</province>
      <city>8</city>
      <location>北京 海淀区</location>
      <description>哼。。。 花样真多。 讨厌。</description>
      <url>http://1</url>
      <profile_image_url>http://tp4.sinaimg.cn/1152759471/50/1263371934</profile_image_url>
      <domain>hotpixel</domain>
      <gender>m</gender>
      <followers_count>1567</followers_count>
      <friends_count>202</friends_count>
      <statuses_count>6776</statuses_count>
      <favourites_count>0</favourites_count>
      <created_at>Fri Aug 28 00:00:00 +0800 2009</created_at>
      <following>false</following>
      <verified>false</verified>
      <allow_all_act_msg>false</allow_all_act_msg>
      <geo_enabled>false</geo_enabled>
    </user>
    <retweeted_status>
      <created_at>Thu Mar 18 19:05:52 +0800 2010</created_at>
      <id>27657268</id>
      <text>班里开始交团费了,跟我没关系</text>
      <source>
        <a href="http://news.sina.com.cn/wap/wbk.html/">新浪微博手机版</a>
      </source>
      <favorited>true</favorited>
      <truncated>false</truncated>
      <geo/>
      <in_reply_to_status_id/>
      <in_reply_to_user_id/>
      <in_reply_to_screen_name/>
      <user>
        <id>1654703984</id>
        <screen_name>高考铅笔亚克西</screen_name>
        <name>高考铅笔亚克西</name>
        <province>42</province>
        <city>1</city>
        <location>湖北 武汉</location>
        <description>在通往高考的路上乳摇狂奔,偶尔发骚回头抛个媚眼骂句操蛋,切不可以为姐就是招之即上挥之自摸的小娘儿们。好不容易成年了,姐要更加有湿想嗯哼。</description>
        <url/>
        <profile_image_url>http://tp1.sinaimg.cn/1654703984/50/1264140632</profile_image_url>
        <domain>kimmy14</domain>
        <gender>f</gender>
        <followers_count>1330</followers_count>
        <friends_count>755</friends_count>
        <statuses_count>3354</statuses_count>
        <favourites_count>0</favourites_count>
        <created_at>Mon Oct 19 00:00:00 +0800 2009</created_at>
        <following>false</following>
        <verified>false</verified>
        <allow_all_act_msg>false</allow_all_act_msg>
        <geo_enabled>false</geo_enabled>
      </user>
    </retweeted_status>
  </status>
  ...
</statuses>

JSON示例

[
    {
        "created_at" : "Thu Mar 18 19:07:05 +0800 2010",
        "text" : "这么小就入党了 敬仰~",
        "truncated" : false,
        "retweeted_status" : 
        {
            "created_at" : "Thu Mar 18 19:05:52 +0800 2010",
            "text" : "班里开始交团费了,跟我没关系",
            "truncated" : false,
            "in_reply_to_status_id" : "",
            "in_reply_to_screen_name" : "",
            "geo" : null,
            "user" : 
            {
                "name" : "高考铅笔亚克西",
                "domain" : "kimmy14",
                "geo_enabled" : false,
                "followers_count" : 1330,
                "statuses_count" : 3354,
                "favourites_count" : 0,
                "city" : "1",
                "description" : "在通往高考的路上乳摇狂奔,偶尔发骚回头抛个媚眼骂句操蛋,切不可以为姐就是招之即上挥之自摸的小娘儿们。好不容易成年了,姐要更加有湿想嗯哼。",
                "verified" : false,
                "id" : 1654703984,
                "gender" : "f",
                "friends_count" : 755,
                "screen_name" : "高考铅笔亚克西",
                "allow_all_act_msg" : false,
                "following" : false,
                "url" : "",
                "profile_image_url" : "http://tp1.sinaimg.cn/1654703984/50/1264140632",
                "created_at" : "Mon Oct 19 00:00:00 +0800 2009",
                "province" : "42",
                "location" : "湖北 武汉"
            },
            "favorited" : true,
            "in_reply_to_user_id" : "",
            "id" : 27657268,
            "source" : "<a href=\"http://news.sina.com.cn/wap/wbk.html/\" rel=\"nofollow\">新浪微博手机版</a>"
        },
        "in_reply_to_status_id" : "",
        "in_reply_to_screen_name" : "",
        "geo" : null,
        "user" : 
        {
            "name" : "老王",
            "domain" : "hotpixel",
            "geo_enabled" : false,
            "followers_count" : 1567,
            "statuses_count" : 6776,
            "favourites_count" : 0,
            "city" : "8",
            "description" : "哼。。。 花样真多。 讨厌。",
            "verified" : false,
            "id" : 1152759471,
            "gender" : "m",
            "friends_count" : 202,
            "screen_name" : "老王",
            "allow_all_act_msg" : false,
            "following" : false,
            "url" : "http://1",
            "profile_image_url" : "http://tp4.sinaimg.cn/1152759471/50/1263371934",
            "created_at" : "Fri Aug 28 00:00:00 +0800 2009",
            "province" : "11",
            "location" : "北京 海淀区"
        },
        "favorited" : true,
        "in_reply_to_user_id" : "",
        "id" : 1,
        "source" : "<a href=\"http://news.sina.com.cn/wap/wbk.html/\" 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 GetFavorites {

	/**
	 * 获取当前用户的收藏列表 
	 * @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).getFavorites();
			for(Status status : list) {
				System.out.println(status.toString());
			}
		} 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验证之版本)
代码示例如下:

//favorites
//获取当前用户的收藏列表 
$c = new WeiboClient( WB_AKEY , 
                      WB_SKEY , 
                      $_SESSION['last_key']['oauth_token'] , 
                      $_SESSION['last_key']['oauth_token_secret']  );
$msg = $c->get_favorites();
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 $status){
	if (isset($status['id']) && isset($status['text'])){
		echo($status['id'].' : '.$status['text'].' ; ');
	}	
}