Statuses/update/en

跳转到: 导航, 搜索

目录

statuses/update

Post a weibo as well as repost a weibo. Request must be handed in POST method.

URL

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

Supported Formats

XML/JSON

HTTP Request Method

POST

Requires Authentication

true
See the Authorization Mechanism Statement for authorization details

Requests Count Limitation

true
See the Interface Access Rights Statement for the Request Count Limitaiton details.

Request Parameters

  Requires Type and Range Description
source true string AppKey for the application to identify it. ( This parameter is not needed when using OAuth)
status true string Weibo content
in_reply_to_status_id false int64 Reposted weibo ID
lat false float Latitude. Range: -90.0 to + 90.0. + stands for Norht latitude.。
long false float Longitude. Range: -180.0 to + 180.0. + stands for East Longitude.
Notes: lat and long need to be used in conjunction with. They’re used to mark the geographical location when the status is updated. It is only activated when geo_enabled=true in the user setting.
annotations false string Metadata. Every weibo can contain one or more metadata to store some information for application itself. Please encode the data into json string, and within 512 characters.

Notes

  • It returns 400 error with “40025:Error: repeated weibo text!“ if user posts a weibo with same content as the last one.
  • • See statuses/repost for the detail of reposting a weibo.

Example Request

XML
curl -u "username:password" -d 'status=abc&annotations=[{"type2":123}]' "http://api.t.sina.com.cn/statuses/update.xml?source=appkey"
JSON
curl -u "username:password" -d 'status=abc&annotations=[{"type2":123}]' "http://api.t.sina.com.cn/statuses/update.json?source=appkey"

Response

XML Example

  <?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 Example

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

Others

Java Example

Please download Java SDK from . Weibo SDK Development Kit Dowload Site
Sample Code:

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 Example

Please download PHP SDK with OAUTH supported from Weibo SDK Development Kit Dowload Site
. Sample Code:

//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"]);