Statuses/update

跳转到: 导航, 搜索
第1行: 第1行:
== statuses/update ==
+
{{api_desc2|
发布一条微博信息。请求必须用POST方式提交。为防止重复,发布的信息与当前最新信息一样话,将会被忽略。
+
uri=statuses/update|
 +
desc=发布一条微博信息。请求必须用POST方式提交。 |
 +
format=XML/JSON|
 +
httpMethod=POST|
 +
needAuth=true|
 +
rateLimit=true|
 +
params={{api_args|status|true|string|要发布的微博消息文本内容}}
 +
{{api_args|in_reply_to_status_id|false|int64|要回复的微博消息ID。如果传入的ID是一条转发的微博,则直接回复最初被转发的微博。}}
 +
{{api_args|lat|false|float|纬度,有效范围:-90.0到+90.0,+表示北纬。}}
 +
{{api_args|long|false|float|经度。有效范围-180.0到+180.0, +表示东经。}}
 +
注意: lat和long参数需配合使用,用于标记发表微博消息时所在的地理位置,只有用户设置中geo_enabled=true时候地理位置信息才有效。|
 +
getParam=|
 +
postParam=-d "status=abc"|
 +
result=
 +
===XML示例===
 +
<pre>
 +
<?xml version="1.0" encoding="UTF-8"?>
 +
<status>
 +
  <created_at>Thu Dec 02 11:53:33 +0800 2010</created_at>
 +
  <id>4016590347</id>
 +
  <text>abc</text>
 +
  <source>
 +
    <a href="http://open.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>1658122963</id>
 +
    <screen_name>zhangwei217245</screen_name>
 +
    <name>zhangwei217245</name>
 +
    <province>11</province>
 +
    <city>5</city>
 +
    <location>北京 朝阳区</location>
 +
    <description>ABCDE</description>
 +
    <url/>
 +
    <profile_image_url>http://tp4.sinaimg.cn/1658122963/50/1282754213</profile_image_url>
 +
    <domain>zhangwei217245</domain>
 +
    <gender>m</gender>
 +
    <followers_count>22</followers_count>
 +
    <friends_count>43</friends_count>
 +
    <statuses_count>104</statuses_count>
 +
    <favourites_count>3</favourites_count>
 +
    <created_at>Tue Nov 03 00:00:00 +0800 2009</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" : "Thu Dec 02 15:17:25 +0800 2010",
 +
    "text" : "为什么欠钱?为什么呀?",
 +
    "truncated" : false,
 +
    "retweeted_status" :
 +
    {
 +
        "created_at" : "Thu Dec 02 13:12:07 +0800 2010",
 +
        "text" : "唉,每天一睁眼就又欠银行100块钱! http://sinaurl.cn/hHjxb",
 +
        "truncated" : false,
 +
        "in_reply_to_status_id" : "",
 +
        "annotations" :
 +
        [
  
{{Api_url|statuses/update}}
+
        ],
 
+
        "in_reply_to_screen_name" : "",
{{Api_format|xml, json}}
+
        "geo" : null,
+
        "user" :
{{Api_req|POST|true|true}}
+
        {
 
+
            "name" : "xiecharll",
=== 请求参数===
+
            "domain" : "xiecharll",
* status.  必填参数, 要更新的微博信息。必须做URLEncode,信息内容不超过140个汉字,为空返回400错误。
+
            "geo_enabled" : true,
* in_reply_to_status_id.  可选参数,@ 需要回复的微博信息ID, 这个参数只有在微博内容以 @username 开头才有意义。(即将推出)。
+
            "followers_count" : 24,
* lat. 可选参数,纬度,发表当前微博所在的地理位置,有效范围 -90.0到+90.0, +表示北纬。只有用户设置中geo_enabled=true时候地理位置才有效。(仅对受邀请的合作开发者开放)
+
            "statuses_count" : 66,
* long.  可选参数,经度。有效范围-180.0到+180.0, +表示东经。(仅对受邀请的合作开发者开放)
+
            "favourites_count" : 3,
 
+
            "city" : "8",
=== 使用说明===
+
            "description" : "蹲在马路中间的人",
 
+
            "verified" : false,
* 如果没有登录或超过发布上限,将返回403错误
+
            "id" : 1646310564,
* 如果in_reply_to_status_id不存在,将返回500错误
+
            "gender" : "m",
* 系统将忽略重复发布的信息。每次发布将比较最后一条发布消息,如果一样将被忽略。因此用户不能连续提交相同信息。
+
            "friends_count" : 24,
 
+
            "screen_name" : "xiecharll",
=== 返回结果 ===
+
            "allow_all_act_msg" : false,
注意geo信息仅对有地理位置的微博才有返回
+
            "following" : false,
XML示例:
+
            "url" : "http://1",
<?xml version="1.0" encoding="UTF-8"?>
+
            "profile_image_url" : "http://tp1.sinaimg.cn/1646310564/50/1252581612/1",
  <status>
+
            "created_at" : "Thu Sep 10 00:00:00 +0800 2009",
    <created_at>Tue Dec 15 13:08:23 +0800 2009</created_at>
+
            "province" : "11",
    <id>2</id>
+
            "location" : "北京 海淀区"
    <text>莱斯科特头上有个月牙型的伤疤,要是他去扮演包公的话可以省去一笔包装费</text>
+
        },
    <source>
+
        "favorited" : false,
      <a href="http://t.sina.com.cn">Web</a>
+
        "in_reply_to_user_id" : "",
    </source>
+
        "id" : 4018420969,
    <favorited>false</favorited>
+
        "source" : "<a href=\"http://t.sina.com.cn\" rel=\"nofollow\">新浪微博</a>"
    <truncated>false</truncated>
+
    },
    <geo xmlns:georss="http://www.georss.org/georss">
+
     "in_reply_to_status_id" : "4018420969",
      <georss:point>23.12 -122.39697</georss:point>
+
     "in_reply_to_screen_name" : "xiecharll",
    </geo>
+
     "geo" : null,
    <in_reply_to_status_id></in_reply_to_status_id>
+
    "user" :
    <in_reply_to_user_id></in_reply_to_user_id>
+
     {
    <in_reply_to_screen_name></in_reply_to_screen_name>
+
        "name" : "zhangwei217245",
    <user>
+
        "domain" : "zhangwei217245",
      <id>135272</id>
+
        "geo_enabled" : true,
      <screen_name>bbb</screen_name>
+
        "followers_count" : 22,
      <name>ddd</name>
+
        "statuses_count" : 107,
      <province>13</province>
+
        "favourites_count" : 3,
      <city>1000</city>
+
        "city" : "5",
      <location>河北</location>
+
         "description" : "ABCDE",
      <description>巾帼不让傻须眉。</description>
+
         "verified" : false,
      <url>http://blog.sina.com.cn</url>
+
        "id" : 1658122963,
      <profile_image_url>http://tp4.sinaimg.cn/1352721827/50/1265540250</profile_image_url>
+
         "gender" : "m",
      <domain>maplelee0723</domain>
+
         "friends_count" : 43,
      <gender>f</gender>
+
         "screen_name" : "zhangwei217245",
      <followers_count>52</followers_count>
+
         "allow_all_act_msg" : false,
      <friends_count>23</friends_count>
+
        "following" : false,
      <statuses_count>54</statuses_count>
+
         "url" : "",
      <favourites_count>0</favourites_count>
+
         "profile_image_url" : "http://tp4.sinaimg.cn/1658122963/50/1282754213",
      <created_at>Tue Jan 26 00:00:00 +0800 2010</created_at>
+
         "created_at" : "Tue Nov 03 00:00:00 +0800 2009",
      <following>false</following>
+
         "province" : "11",
      <verified>false</verified>
+
         "location" : "北京 朝阳区"
      <allow_all_act_msg>false</allow_all_act_msg>
+
    },
      <geo_enabled>false</geo_enabled>
+
    "favorited" : false,
    </user>
+
    "in_reply_to_user_id" : "1646310564",
  </status>
+
    "id" : 4020927147,
 
+
    "source" : "<a href=\"http://open.t.sina.com.cn\" rel=\"nofollow\">微博开放平台接口</a>"
JSON示例:
+
}
 
+
</pre>|
    {"created_at":"Wed Jan 06 19:38:33 +0800 2010",
+
useAge=
    "id":142280,
+
为防止重复提交,当用户发布的微博消息与上次成功发布的微博消息内容一样时,将返回400错误,给出错误提示:“40025:Error: repeated weibo text!“。|
    "text":"111111111111111111111",
+
otherInfo=
    "source":"<a id=\"0\" href=\"http://t.sina.com.cn/\" rel=\"nofollow\">Web</a>",
+
===Java示例===
     "favorited":false,
+
     "truncated":false,
+
     "in_reply_to_status_id":"",
+
     "in_reply_to_user_id":"",
+
    "in_reply_to_screen_name":"",
+
    "geo":{"type": "Point","coordinates": [23.12 -122.39697]},
+
    "user":{"id":11057,
+
         "screen_name":"name_11057",
+
         "name":"name_11057",
+
         "province":"0",
+
         "city":"0",
+
         "location":"",
+
         "description":"",
+
         "url":"",
+
         "profile_image_url":"http://tp2.sinaimg.cn/11057/50/0",
+
         "domain":"11057",
+
         "followers_count":19,
+
        "friends_count":101,
+
         "statuses_count":0,
+
        "favourites_count":3,
+
        "created_at":"Thu Jan 01 08:00:00 +0800 1970",
+
        "following":false,
+
        "geo_enabled":false,
+
        "verified":false}
+
    }
+
{{Param_status}}
+
{{Param_user}}
+
 
+
=== 使用示例===
+
 
+
* xml:
+
curl -u uid:password -d "source=appkey&status=playing with cURL and the Sina API" http://api.t.sina.com.cn/statuses/update.xml
+
 
+
* json:
+
curl -u uid:password -d "source=appkey&status=playing with cURL and the Sina API" http://api.t.sina.com.cn/statuses/update.json
+
 
+
====Java示例====
+
 
请从 [[SDK | 微博SDK开发包下载]] 下载Java SDK<br>
 
请从 [[SDK | 微博SDK开发包下载]] 下载Java SDK<br>
 
代码示意如下:
 
代码示意如下:
第143行: 第173行:
 
  }
 
  }
 
  }
 
  }
====PHP示例====
+
===PHP示例===
 
请从 [[SDK | 微博SDK开发包下载]] 处下载PHP SDK(支持OAuth验证之版本)<br>  
 
请从 [[SDK | 微博SDK开发包下载]] 处下载PHP SDK(支持OAuth验证之版本)<br>  
 
代码示例如下:
 
代码示例如下:
第164行: 第194行:
 
echo($msg['id']." : ".$msg['text']." ".$msg["created_at"]);
 
echo($msg['id']." : ".$msg['text']." ".$msg["created_at"]);
 
</pre>
 
</pre>
 +
}}

2010年12月2日 (四) 15:18的版本

目录

statuses/update

发布一条微博信息。请求必须用POST方式提交。

URL

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

支持格式

XML/JSON

HTTP请求方式

POST

是否需要登录

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

请求数限制

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

请求参数

  必选 类型及范围 说明
source true string 申请应用时分配的AppKey,调用接口时候代表应用的唯一身份。(采用OAuth授权方式不需要此参数)
status true string 要发布的微博消息文本内容
in_reply_to_status_id false int64 要回复的微博消息ID。如果传入的ID是一条转发的微博,则直接回复最初被转发的微博。
lat false float 纬度,有效范围:-90.0到+90.0,+表示北纬。
long false float 经度。有效范围-180.0到+180.0, +表示东经。

注意: lat和long参数需配合使用,用于标记发表微博消息时所在的地理位置,只有用户设置中geo_enabled=true时候地理位置信息才有效。

注意事项

为防止重复提交,当用户发布的微博消息与上次成功发布的微博消息内容一样时,将返回400错误,给出错误提示:“40025:Error: repeated weibo text!“。

返回结果

XML示例

<?xml version="1.0" encoding="UTF-8"?>
<status>
  <created_at>Thu Dec 02 11:53:33 +0800 2010</created_at>
  <id>4016590347</id>
  <text>abc</text>
  <source>
    <a href="http://open.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>1658122963</id>
    <screen_name>zhangwei217245</screen_name>
    <name>zhangwei217245</name>
    <province>11</province>
    <city>5</city>
    <location>北京 朝阳区</location>
    <description>ABCDE</description>
    <url/>
    <profile_image_url>http://tp4.sinaimg.cn/1658122963/50/1282754213</profile_image_url>
    <domain>zhangwei217245</domain>
    <gender>m</gender>
    <followers_count>22</followers_count>
    <friends_count>43</friends_count>
    <statuses_count>104</statuses_count>
    <favourites_count>3</favourites_count>
    <created_at>Tue Nov 03 00:00:00 +0800 2009</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" : "Thu Dec 02 15:17:25 +0800 2010",
    "text" : "为什么欠钱?为什么呀?",
    "truncated" : false,
    "retweeted_status" : 
    {
        "created_at" : "Thu Dec 02 13:12:07 +0800 2010",
        "text" : "唉,每天一睁眼就又欠银行100块钱! http://sinaurl.cn/hHjxb",
        "truncated" : false,
        "in_reply_to_status_id" : "",
        "annotations" : 
        [

        ],
        "in_reply_to_screen_name" : "",
        "geo" : null,
        "user" : 
        {
            "name" : "xiecharll",
            "domain" : "xiecharll",
            "geo_enabled" : true,
            "followers_count" : 24,
            "statuses_count" : 66,
            "favourites_count" : 3,
            "city" : "8",
            "description" : "蹲在马路中间的人",
            "verified" : false,
            "id" : 1646310564,
            "gender" : "m",
            "friends_count" : 24,
            "screen_name" : "xiecharll",
            "allow_all_act_msg" : false,
            "following" : false,
            "url" : "http://1",
            "profile_image_url" : "http://tp1.sinaimg.cn/1646310564/50/1252581612/1",
            "created_at" : "Thu Sep 10 00:00:00 +0800 2009",
            "province" : "11",
            "location" : "北京 海淀区"
        },
        "favorited" : false,
        "in_reply_to_user_id" : "",
        "id" : 4018420969,
        "source" : "<a href=\"http://t.sina.com.cn\" rel=\"nofollow\">新浪微博</a>"
    },
    "in_reply_to_status_id" : "4018420969",
    "in_reply_to_screen_name" : "xiecharll",
    "geo" : null,
    "user" : 
    {
        "name" : "zhangwei217245",
        "domain" : "zhangwei217245",
        "geo_enabled" : true,
        "followers_count" : 22,
        "statuses_count" : 107,
        "favourites_count" : 3,
        "city" : "5",
        "description" : "ABCDE",
        "verified" : false,
        "id" : 1658122963,
        "gender" : "m",
        "friends_count" : 43,
        "screen_name" : "zhangwei217245",
        "allow_all_act_msg" : false,
        "following" : false,
        "url" : "",
        "profile_image_url" : "http://tp4.sinaimg.cn/1658122963/50/1282754213",
        "created_at" : "Tue Nov 03 00:00:00 +0800 2009",
        "province" : "11",
        "location" : "北京 朝阳区"
    },
    "favorited" : false,
    "in_reply_to_user_id" : "1646310564",
    "id" : 4020927147,
    "source" : "<a href=\"http://open.t.sina.com.cn\" rel=\"nofollow\">微博开放平台接口</a>"
}

其他

Java示例

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

package weibo4j.examples;

import weibo4j.Status;
import weibo4j.Weibo; 

public class UpdateStatus { 

	/**
	 * 发布一条微博信息 
	 * @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);
       	Status status = weibo.updateStatus("测试发表微博");
       	System.out.println(status.getId() + " : "+ status.getText()+"  "+status.getCreatedAt());
       	
		} 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/update
$c = new WeiboClient( WB_AKEY , 
                      WB_SKEY , 
                      $_SESSION['last_key']['oauth_token'] , 
                      $_SESSION['last_key']['oauth_token_secret']  );

$msg = $c->update("测试发表微博");
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;
} 
echo($msg['id']." : ".$msg['text']." ".$msg["created_at"]);