Favorites/create

跳转到: 导航, 搜索
 
(未显示4个用户的10个中间版本)
第1行: 第1行:
== favorites/create ==
+
{{api_desc2|
收藏一条微博信息
+
uri=favorites/create|
 
+
desc=收藏一条微博消息。|
=== URL===
+
format=XML/JSON|
curl http://api.t.sina.com.cn/favorites/create.format
+
httpMethod=POST|
+
needAuth=true|
=== 格式===
+
rateLimit=true|
xml, json
+
params={{api_args|id|true|int64|要收藏的微博消息ID。}}|
+
getParam=&id=12345|
=== HTTP请求方式===
+
postParam=|
POST
+
result=
+
===XML示例===
=== 是否需要身份验证===
+
<pre>
true
+
<?xml version="1.0" encoding="UTF-8"?>
+
    <status>
=== 请求数限制===
+
     <created_at>Mon Nov 29 16:08:43 +0800 2010</created_at>
false
+
     <id>3958728723</id>
 
+
     <text>各位开发者,我们的论坛上线啦~http://sinaurl.cn/h4FWc7 欢迎大家的参与~另外,关于技术相关的问题,可以在论坛上提出,也可以@微博API 这个官方技术支持账号哦~感谢大家对开放平台的支持~[呵呵]</text>
=== 请求参数===
+
* id 必填参数, 要收藏的微博id
+
 
+
 
+
=== 使用说明===
+
* 如果没有登录或超过发布上限,将返回403错误
+
* 收藏ID不存在,将返回500错误
+
* 收藏成功返回收藏的微博信息
+
 
+
=== 返回结果 ===
+
XML示例:
+
<?xml version="1.0" encoding="UTF-8"?>
+
  <status>
+
     <created_at>Fri Jan 08 10:18:05 +0800 2010</created_at>
+
     <id>142314</id>
+
     <text>lsdjfl55</text>
+
 
     <source>
 
     <source>
       <a id="10013" href="http://t.sina.com.cn">SinaDestTop</a>
+
       <a href="http://t.sina.com.cn">新浪微博</a>
 
     </source>
 
     </source>
     <favorited>true</favorited>
+
     <favorited>false</favorited>
 
     <truncated>false</truncated>
 
     <truncated>false</truncated>
 
     <geo/>
 
     <geo/>
     <in_reply_to_status_id></in_reply_to_status_id>
+
     <in_reply_to_status_id/>
     <in_reply_to_user_id></in_reply_to_user_id>
+
     <in_reply_to_user_id/>
     <in_reply_to_screen_name></in_reply_to_screen_name>
+
     <in_reply_to_screen_name/>
 
     <user>
 
     <user>
       <id>11075</id>
+
       <id>11051</id>
       <screen_name>name_11075</screen_name>
+
       <screen_name>微博开放平台</screen_name>
       <name>name_11075</name>
+
       <name>微博开放平台</name>
       <province>0</province>
+
       <province>11</province>
       <city>0</city>
+
       <city>8</city>
       <location></location>
+
       <location>北京 海淀区</location>
       <description></description>
+
       <description>新浪微博开放平台市场推广官方账号,如有技术问题,请@微博API或者发私信给微博API</description>
       <profile_image_url>http://tp4.sinaimg.cn/11075/50/0</profile_image_url>
+
      <url>http://open.t.sina.com.cn/</url>
       <domain>11075</domain>
+
       <profile_image_url>http://tp4.sinaimg.cn/11051/50/1280283165/1</profile_image_url>
       <gender></gender>
+
       <domain>openapi</domain>
      <email></email>
+
       <gender>m</gender>
      <qq>4102</qq>
+
       <followers_count>13034</followers_count>
      <msn>msn_4102</msn>
+
       <friends_count>5</friends_count>
       <followers_count>28</followers_count>
+
       <statuses_count>157</statuses_count>
       <friends_count>50</friends_count>
+
       <favourites_count>0</favourites_count>
       <statuses_count>0</statuses_count>
+
       <created_at>Wed Jan 20 00:00:00 +0800 2010</created_at>
       <favourites_count>34</favourites_count>
+
       <created_at>Thu Jan 01 08:00:00 +0800 1970</created_at>
+
 
       <following>false</following>
 
       <following>false</following>
 
       <verified>true</verified>
 
       <verified>true</verified>
       <geo_enabled>false</geo_enabled>
+
      <allow_all_act_msg>true</allow_all_act_msg>
 +
       <geo_enabled>true</geo_enabled>
 
     </user>
 
     </user>
 
   </status>
 
   </status>
 +
</pre>
 +
===JSON示例===
 +
<pre>
 +
    {
 +
        "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>"
 +
    }
 +
</pre>|
 +
useAge=
 +
* 如果没有登录或超过频率限制,将返回403错误
 +
* 收藏ID不存在,将返回400错误
 +
* 收藏成功返回收藏的微博信息|
 +
otherInfo=
 +
===Java示例===
 +
请从 [[SDK | 微博SDK开发包下载]] 下载Java SDK<br>
 +
代码示例如下:
 +
package weibo4j.examples;
 +
 +
import java.util.List;
 +
import weibo4j.Status;
 +
import weibo4j.Weibo;
 +
import weibo4j.WeiboException;
 +
 +
public class CreateFavorite {
 +
 +
/**
 +
* 添加收藏
 +
* @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 {
 +
                //args[2]:收藏id
 +
Status status = getWeibo(true,args).createFavorite(Long.parseLong(args[2]));
 +
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;
 +
}
 +
}
  
JSON示例:
+
===PHP示例===
 
+
请从 [[SDK | 微博SDK开发包下载]] 处下载PHP SDK(支持OAuth验证之版本)<br>  
  {"created_at":"Fri Jan 08 10:18:05 +0800 2010",
+
代码示例如下:
    "id":142314,
+
<pre>
    "text":"lsdjfl55",
+
//favorites/create
    "source":"<a id=\"10013\" href=\"http://t.sina.com.cn/\" rel=\"nofollow\">SinaDestTop</a>",
+
//添加收藏
    "favorited":true,
+
$c = new WeiboClient( WB_AKEY ,  
    "truncated":false,
+
                      WB_SKEY ,  
    "in_reply_to_status_id":"",
+
                      $_SESSION['last_key']['oauth_token'] ,  
    "in_reply_to_user_id":"",
+
                      $_SESSION['last_key']['oauth_token_secret']  );
    "in_reply_to_screen_name":"",
+
//收藏id
    "geo":null,
+
$sid='sid';
    "user":
+
$msg = $c->add_to_favorites( $sid );
        {"id":11075,
+
if ($msg === false || $msg === null){
          "screen_name":"name_11075",
+
echo "Error occured";
          "name":"name_11075",
+
return false;
          "province":"0",
+
}
          "city":"0",
+
if (isset($msg['error_code']) && isset($msg['error'])){
          "location":"",
+
echo ('Error_code: '.$msg['error_code'].';  Error: '.$msg['error'] );
          "description":"",
+
return false;
          "profile_image_url":"http://tp4.sinaimg.cn/11075/50/0",
+
}
          "domain":"11075",
+
if ($msg['text']){
          "email":"",
+
echo($msg['text']);
          "qq":"4102",
+
}
          "msn":"msn_4102",
+
</pre>
          "followers_count":28,
+
}}
          "friends_count":50,
+
          "statuses_count":0,
+
          "favourites_count":34,
+
          "created_at":"Thu Jan 01 08:00:00 +0800 1970",
+
          "following":false,
+
          "geo_enabled":false,
+
          "verified":true},
+
    "apiState":3}
+
 
+
=== 使用示例===
+
 
+
* xml:
+
 
+
curl -u user:password -d "id=12345" http://api.t.sina.com.cn/favorites/create.xml
+
 
+
* json:
+
 
+
curl -u user:password -d "id=12345" http://api.t.sina.com.cn/favorites/create.json
+

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

目录

favorites/create

收藏一条微博消息。

URL

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

支持格式

XML/JSON

HTTP请求方式

POST

是否需要登录

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

请求数限制

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

请求参数

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

注意事项

  • 如果没有登录或超过频率限制,将返回403错误
  • 收藏ID不存在,将返回400错误
  • 收藏成功返回收藏的微博信息

返回结果

XML示例

<?xml version="1.0" encoding="UTF-8"?>
    <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>

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>"
    }

其他

Java示例

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

package weibo4j.examples;

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

public class CreateFavorite {

	/**
	 * 添加收藏 
	 * @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 {
               //args[2]:收藏id
		Status status = getWeibo(true,args).createFavorite(Long.parseLong(args[2]));
		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/create
//添加收藏 
$c = new WeiboClient( WB_AKEY , 
                      WB_SKEY , 
                      $_SESSION['last_key']['oauth_token'] , 
                      $_SESSION['last_key']['oauth_token_secret']  );
//收藏id
$sid='sid';
$msg = $c->add_to_favorites( $sid );
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 ($msg['text']){
	echo($msg['text']);
}
文档更新时间: 2012-09-24