Statuses/update

跳转到: 导航, 搜索
(statuses/update)
 
(未显示7个用户的56个中间版本)
第1行: 第1行:
== statuses/update ==
+
{{api_desc2|
发布一条微薄信息。要求必须填写下面的status参数。请求必须用POST方式提交。为防止重复,发布的信息与当前最新信息一样话,将会被忽略。
+
uri=statuses/update|
 
+
desc=发布一条微博信息。也可以同时转发某条微博。请求必须用POST方式提交。 |
Updates the authenticating user's status. Requires the status parameter specified below. Request must be a POST. A status update with text identical to the authenticating user's current status will be ignored to prevent duplicates.
+
format=XML/JSON|
 
+
httpMethod=POST|
=== URL: ===
+
needAuth=true|
curl http://api.t.sina.com.cn/sstatuses/update.format
+
rateLimit=true|
 +
params={{api_args|status|true|string|要发布的微博消息文本内容}}
 +
{{api_args|in_reply_to_status_id|false|int64|要转发的微博消息ID。}}
 +
{{api_args|lat|false|float|纬度。有效范围:-90.0到+90.0,+表示北纬。}}
 +
{{api_args|long|false|float|经度。有效范围:-180.0到+180.0,+表示东经。}}
 +
{{api_args_colspan|1=<font style="color:#ee6666">注意:lat和long参数需配合使用,用于标记发表微博消息时所在的地理位置,只有用户设置中geo_enabled=true时候地理位置信息才有效。</font>}}
 +
{{api_args|annotations|false|string|元数据,主要是为了方便第三方应用记录一些适合于自己使用的信息。<br/>每条微博可以包含一个或者多个元数据。请以<b>json字串</b>的形式提交,字串长度不超过512个字符,具体内容可以自定。}}|
 +
getParam=|
 +
postParam=-d 'status=abc&annotations=[{"type2":123}]'|
 +
result=
 +
===XML示例===
 +
<pre>
 +
  <?xml version="1.0" encoding="UTF-8"?>
 +
  <status>
 +
    <created_at>Mon Dec 13 14:55:05 +0800 2010</created_at>
 +
    <id>4288554507</id>
 +
    <text>abcedf</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_status_id>
 +
    <in_reply_to_user_id></in_reply_to_user_id>
 +
    <in_reply_to_screen_name></in_reply_to_screen_name>
 +
    <user>
 +
      <id>1854740027</id>
 +
      <screen_name>siegetest</screen_name>
 +
      <name>siegetest</name>
 +
      <province>11</province>
 +
      <city>8</city>
 +
      <location>北京 海淀区</location>
 +
      <description>ABCDE</description>
 +
      <url></url>
 +
      <profile_image_url>http://tp4.sinaimg.cn/1854740027/50/1291272213/1</profile_image_url>
 +
      <domain></domain>
 +
      <gender>m</gender>
 +
      <followers_count>2</followers_count>
 +
      <friends_count>20</friends_count>
 +
      <statuses_count>39</statuses_count>
 +
      <favourites_count>0</favourites_count>
 +
      <created_at>Thu Nov 11 00:00:00 +0800 2010</created_at>
 +
      <following>false</following>
 +
      <verified>false</verified>
 +
      <allow_all_act_msg>true</allow_all_act_msg>
 +
      <geo_enabled>true</geo_enabled>
 +
    </user>
 +
    <annotations>
 +
      <annotation class="object">
 +
        <type2 type="number">123</type2>
 +
      </annotation>
 +
    </annotations>
 +
  </status>
 +
</pre>
 +
===JSON示例===
 +
<pre>
 +
{
 +
    "created_at" : "Mon Dec 13 14:56:03 +0800 2010",
 +
    "text" : "abc",
 +
    "truncated" : false,
 +
    "in_reply_to_status_id" : "",
 +
    "annotations" :
 +
    [
 +
        {
 +
            "type2" : 123
 +
        }
 +
    ],
 +
    "in_reply_to_screen_name" : "",
 +
    "geo" : null,
 +
    "user" :
 +
    {
 +
        "name" : "siegetest2",
 +
        "domain" : "",
 +
        "geo_enabled" : true,
 +
        "followers_count" : 0,
 +
        "statuses_count" : 3,
 +
        "favourites_count" : 0,
 +
        "city" : "8",
 +
        "description" : "",
 +
        "verified" : false,
 +
        "id" : 1854835127,
 +
        "gender" : "m",
 +
        "friends_count" : 20,
 +
        "screen_name" : "siegetest2",
 +
        "allow_all_act_msg" : false,
 +
        "following" : false,
 +
        "url" : "",
 +
        "profile_image_url" : "http://tp4.sinaimg.cn/1854835127/50/1291709848/1",
 +
        "created_at" : "Thu Nov 11 00:00:00 +0800 2010",
 +
        "province" : "11",
 +
        "location" : "北京 海淀区"
 +
    },
 +
    "favorited" : false,
 +
    "in_reply_to_user_id" : "",
 +
    "id" : 4288574373,
 +
    "source" : "<a href=\"http://open.t.sina.com.cn\" rel=\"nofollow\">微博开放平台接口</a>"
 +
}
 +
</pre>|
 +
useAge=
 +
* 为防止重复提交,当用户发布的微博消息与上次成功发布的微博消息内容一样时,将返回400错误,给出错误提示:“40025:Error: repeated weibo text!“。
 +
* 转发微博消息时接口的表现可参考[[statuses/repost]]|
 +
otherInfo=
 +
===Java示例===
 +
请从 [[SDK | 微博SDK开发包下载]] 下载Java SDK<br>
 +
代码示意如下:
 +
package weibo4j.examples;
 
   
 
   
=== Formats: ===
+
  import weibo4j.Status;
xml, json, rss, atom
+
import weibo4j.Weibo;
 
   
 
   
=== HTTP Method(s): ===
+
public class UpdateStatus {
POST
+
 
   
 
   
=== Requires Authentication (about authentication): ===
+
/**
true
+
* 发布一条微博信息
 +
* @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();
 +
}
 +
}
 
   
 
   
=== API rate limited (about rate limiting): ===
+
private static Weibo getWeibo(boolean isOauth,String ... args) {
false
+
Weibo weibo = new Weibo();
 
+
if(isOauth) {//oauth验证方式 args[0]:访问的token;args[1]:访问的密匙
=== Parameters: ===
+
weibo.setToken(args[0], args[1]);
* status.  必填参数, 要更新的微薄信息。必须做URLEncode,信息内容部超过140个汉字。
+
}else {//用户登录方式
* in_reply_to_status_id. 选填参数. 更新现有的微薄信息的ID号。
+
    weibo.setUserId(args[0]);//用户名/ID
o Note: 如果不是微薄信息发布人或发布人提到的用户,此参数将被忽略
+
    weibo.setPassword(args[1]);//密码
* lat. 选填参数.暂不支持
+
}
* long.  选填参数.暂不支持
+
return weibo;
 
+
}
 
+
}
* status.  Required.  The text of your status update. URL encode as necessary. Statuses over 140 characters will be forceably truncated.
+
===PHP示例===
* in_reply_to_status_id.  Optional. The ID of an existing status that the update is in reply to.
+
请从 [[SDK | 微博SDK开发包下载]] 处下载PHP SDK(支持OAuth验证之版本)<br>  
o Note: This parameter will be ignored unless the author of the tweet this parameter references is mentioned within the status text. Therefore, you must include @username, where username is the author of the referenced tweet, within the update.
+
代码示例如下:
* lat. Optional. The location's latitude that this tweet refers to.  [COMING SOON]  
+
<pre>
o Note: The valid ranges for latitude is -90.0 to +90.0 (North is positive) inclusive.  This parameter will be ignored if outside that range, if it is not a number, if geo_enabled is disabled, or if there not a corresponding long parameter with this tweet.
+
//Statuses/update
* long. Optional. The location's longitude that this tweet refers to.  [COMING SOON]  
+
$c = new WeiboClient( WB_AKEY ,
o Note: The valid ranges for longitude is -180.0 to +180.0 (East is positive) inclusive.  This parameter will be ignored if outside that range, if it is not a number, if geo_enabled is disabled, or if there not a corresponding lat parameter with this tweet.
+
                      WB_SKEY ,  
 
+
                      $_SESSION['last_key']['oauth_token'] ,
=== Usage Notes: ===
+
                      $_SESSION['last_key']['oauth_token_secret']  );
* 如果没有登录或越权发布,将返回403错误
+
* 微薄将忽略重复的发布。每次发布将比较登录用户的最新一条发布消息,如果一样将被忽略。因此,用户不能连续提交相同信息。 发布成功返回发布的信息ID,否则返回为空。
+
 
+
* This method is subject to update limits. A HTTP 403 will be returned if this limit as been hit.
+
* Twitter will ignore attempts to perform a duplicate update. With each update attempt, the application compares the update text with the authenticating user's last successful update, and ignores any attempts that would result in duplication. Therefore, a user cannot submit the same status twice in a row. The status element in the response will return the id from the previously successful update if a duplicate has been silently ignored.
+
 
+
=== Geolocation [COMING SOON]: ===
+
* Any geolocation parameters in the update will be ignored if geo_enabled for the user is false (this is the default setting for all users unless the user has enabled geolocation in their settings)
+
* The XML response uses GeoRSS to encode the latitude and longitude. <georss:point> encodes as latitude, space, and longitude (see the response below for an example).  For JSON the response uses conventions laid forth in GeoJSON which looks like 
+
"geo":
+
 
+
{
+
 
+
"type":"Point",
+
 
+
"coordinates":[37.78029, -122.39697]
+
  
 +
$msg = $c->update("测试发表微博");
 +
if ($msg === false || $msg === null){
 +
echo "Error occured";
 +
return false;
 
}
 
}
* If there is no geolocated information for a status, then there will be an empty <geo/> or "geo" : {}. 
+
if (isset($msg['error_code']) && isset($msg['error'])){
* Currently, all geolocated information will be removed after seven days. 
+
echo ('Error_code: '.$msg['error_code'].';  Error: '.$msg['error'] );
 
+
return false;
=== Response ===
+
}
(about return values): XML example (truncated):
+
echo($msg['id']." : ".$msg['text']." ".$msg["created_at"]);
<?xml version="1.0" encoding="UTF-8"?>
+
</pre>
<status>
+
}}
  <created_at>Tue Apr 07 22:52:51 +0000 2009</created_at>
+
  <id>1472669360</id>
+
  <text>At least I can get your humor through tweets. RT @abdur: I don't mean this in a bad way, but genetically speaking your a cul-de-sac.</text>
+
  <source><a href="http://www.tweetdeck.com/">TweetDeck</a></source>
+
  <truncated>false</truncated>
+
  <in_reply_to_status_id>1472669230</in_reply_to_status_id>
+
  <in_reply_to_user_id>10759032</in_reply_to_user_id>
+
  <favorited>false</favorited>
+
  <in_reply_to_screen_name></in_reply_to_screen_name>
+
  <!-- Not yet part of the current payload.  [COMING SOON] -->
+
  <geo xmlns:georss="http://www.georss.org/georss">
+
  <georss:point>37.78029 -122.39697</georss:point>
+
  </geo>
+
  <user>
+
  <id>1401881</id>
+
  <name>Doug Williams</name>
+
  <screen_name>dougw</screen_name>
+
  <location>San Francisco, CA</location>
+
  <description>Twitter API Support. Internet, greed, users, dougw and opportunities are my passions.</description>
+
  <profile_image_url>http://s3.amazonaws.com/twitter_production/profile_images/59648642/avatar_normal.png</profile_image_url>
+
  <url>http://www.igudo.com</url>
+
  <protected>false</protected>
+
  <followers_count>1027</followers_count>
+
  <profile_background_color>9ae4e8</profile_background_color>
+
  <profile_text_color>000000</profile_text_color>
+
  <profile_link_color>0000ff</profile_link_color>
+
  <profile_sidebar_fill_color>e0ff92</profile_sidebar_fill_color>
+
  <profile_sidebar_border_color>87bc44</profile_sidebar_border_color>
+
  <friends_count>293</friends_count>
+
  <created_at>Sun Mar 18 06:42:26 +0000 2007</created_at>
+
  <favourites_count>0</favourites_count>
+
  <utc_offset>-18000</utc_offset>
+
  <time_zone>Eastern Time (US & Canada)</time_zone>
+
  <profile_background_image_url>http://s3.amazonaws.com/twitter_production/profile_background_images/2752608/twitter_bg_grass.jpg</profile_background_image_url>
+
  <profile_background_tile>false</profile_background_tile>
+
  <statuses_count>3390</statuses_count>
+
  <notifications>false</notifications>
+
  <following>false</following>
+
  <geo_enabled>true</geo_enabled> <!-- Not yet part of the current payload.  [COMING SOON] -->
+
  <verified>true</verified>
+
  </user>
+
</status>
+
 
+
 
+
 
+
=== Usage examples: ===
+
cURL (about cURL):
+
 
+
curl -u user:password -d "status=playing with cURL and the Twitter API" http://api.t.sina.com.cn/statuses/update.xml
+

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

目录

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。
lat false float 纬度。有效范围:-90.0到+90.0,+表示北纬。
long false float 经度。有效范围:-180.0到+180.0,+表示东经。
注意:lat和long参数需配合使用,用于标记发表微博消息时所在的地理位置,只有用户设置中geo_enabled=true时候地理位置信息才有效。
annotations false string 元数据,主要是为了方便第三方应用记录一些适合于自己使用的信息。
每条微博可以包含一个或者多个元数据。请以json字串的形式提交,字串长度不超过512个字符,具体内容可以自定。

注意事项

  • 为防止重复提交,当用户发布的微博消息与上次成功发布的微博消息内容一样时,将返回400错误,给出错误提示:“40025:Error: repeated weibo text!“。
  • 转发微博消息时接口的表现可参考statuses/repost

返回结果

XML示例

  <?xml version="1.0" encoding="UTF-8"?>
  <status>
    <created_at>Mon Dec 13 14:55:05 +0800 2010</created_at>
    <id>4288554507</id>
    <text>abcedf</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_status_id>
    <in_reply_to_user_id></in_reply_to_user_id>
    <in_reply_to_screen_name></in_reply_to_screen_name>
    <user>
      <id>1854740027</id>
      <screen_name>siegetest</screen_name>
      <name>siegetest</name>
      <province>11</province>
      <city>8</city>
      <location>北京 海淀区</location>
      <description>ABCDE</description>
      <url></url>
      <profile_image_url>http://tp4.sinaimg.cn/1854740027/50/1291272213/1</profile_image_url>
      <domain></domain>
      <gender>m</gender>
      <followers_count>2</followers_count>
      <friends_count>20</friends_count>
      <statuses_count>39</statuses_count>
      <favourites_count>0</favourites_count>
      <created_at>Thu Nov 11 00:00:00 +0800 2010</created_at>
      <following>false</following>
      <verified>false</verified>
      <allow_all_act_msg>true</allow_all_act_msg>
      <geo_enabled>true</geo_enabled>
    </user>
    <annotations>
      <annotation class="object">
        <type2 type="number">123</type2>
      </annotation>
    </annotations>
  </status>

JSON示例

{
    "created_at" : "Mon Dec 13 14:56:03 +0800 2010",
    "text" : "abc",
    "truncated" : false,
    "in_reply_to_status_id" : "",
    "annotations" : 
    [
        {
            "type2" : 123
        }
    ],
    "in_reply_to_screen_name" : "",
    "geo" : null,
    "user" : 
    {
        "name" : "siegetest2",
        "domain" : "",
        "geo_enabled" : true,
        "followers_count" : 0,
        "statuses_count" : 3,
        "favourites_count" : 0,
        "city" : "8",
        "description" : "",
        "verified" : false,
        "id" : 1854835127,
        "gender" : "m",
        "friends_count" : 20,
        "screen_name" : "siegetest2",
        "allow_all_act_msg" : false,
        "following" : false,
        "url" : "",
        "profile_image_url" : "http://tp4.sinaimg.cn/1854835127/50/1291709848/1",
        "created_at" : "Thu Nov 11 00:00:00 +0800 2010",
        "province" : "11",
        "location" : "北京 海淀区"
    },
    "favorited" : false,
    "in_reply_to_user_id" : "",
    "id" : 4288574373,
    "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"]);
文档更新时间: 2012-09-24