Statuses/update 带元数据
(创建新页面为 '== statuses/update == 发布一条微博信息。请求必须用POST方式提交。为防止重复,发布的信息与当前最新信息一样话,将会被忽略。 === URL=…') |
|||
第1行: | 第1行: | ||
− | + | {{api_desc2| | |
− | + | 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。}} | |
− | = | + | {{api_args|lat|false|float|纬度。有效范围:-90.0到+90.0,+表示北纬。}} |
− | POST | + | {{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个字符,具体内容可以自定。}}| |
− | true | + | getParam=| |
− | + | postParam=-d 'status=abc&annotations=[{"type":{"app_mid":"123456abc","push_cmt":123,"attach":111}},{"type2":{"app_xmid":123}}]'| | |
− | = | + | result= |
− | true | + | ===XML示例=== |
− | + | <pre> | |
− | = | + | <?xml version="1.0" encoding="UTF-8"?> |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | === | + | |
− | + | ||
− | + | ||
− | + | ||
<status> | <status> | ||
− | <created_at> | + | <created_at>Mon Dec 13 14:41:15 +0800 2010</created_at> |
− | <id> | + | <id>4288263839</id> |
− | <text> | + | <text>abcedf</text> |
<source> | <source> | ||
− | <a href="http://t.sina.com.cn"> | + | <a href="http://open.t.sina.com.cn">微博开放平台接口</a> |
</source> | </source> | ||
<favorited>false</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_status_id> | ||
<in_reply_to_user_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></in_reply_to_screen_name> | ||
<user> | <user> | ||
− | <id> | + | <id>1854740027</id> |
− | <screen_name> | + | <screen_name>siegetest</screen_name> |
− | <name> | + | <name>siegetest</name> |
− | <province> | + | <province>11</province> |
− | <city> | + | <city>8</city> |
− | <location> | + | <location>北京 海淀区</location> |
− | <description> | + | <description>ABCDE</description> |
− | <url> | + | <url></url> |
− | <profile_image_url>http://tp4.sinaimg.cn/ | + | <profile_image_url>http://tp4.sinaimg.cn/1854740027/50/1291272213/1</profile_image_url> |
− | <domain> | + | <domain></domain> |
− | <gender> | + | <gender>m</gender> |
− | <followers_count> | + | <followers_count>2</followers_count> |
− | <friends_count> | + | <friends_count>20</friends_count> |
− | <statuses_count> | + | <statuses_count>38</statuses_count> |
<favourites_count>0</favourites_count> | <favourites_count>0</favourites_count> | ||
− | <created_at> | + | <created_at>Thu Nov 11 00:00:00 +0800 2010</created_at> |
<following>false</following> | <following>false</following> | ||
<verified>false</verified> | <verified>false</verified> | ||
− | <allow_all_act_msg> | + | <allow_all_act_msg>true</allow_all_act_msg> |
− | <geo_enabled> | + | <geo_enabled>true</geo_enabled> |
</user> | </user> | ||
+ | <annotations> | ||
+ | <annotation class="object"> | ||
+ | <type class="object"> | ||
+ | <app_mid type="string">123456abc</app_mid> | ||
+ | <attach type="number">111</attach> | ||
+ | <push_cmt type="number">123</push_cmt> | ||
+ | </type> | ||
+ | </annotation> | ||
+ | <annotation class="object"> | ||
+ | <type2 class="object"> | ||
+ | <app_xmid type="number">123</app_xmid> | ||
+ | </type2> | ||
+ | </annotation> | ||
+ | </annotations> | ||
</status> | </status> | ||
+ | </pre> | ||
+ | ===JSON示例=== | ||
+ | <pre> | ||
+ | { | ||
+ | "created_at" : "Mon Dec 13 14:46:10 +0800 2010", | ||
+ | "text" : "abc", | ||
+ | "truncated" : false, | ||
+ | "in_reply_to_status_id" : "", | ||
+ | "annotations" : | ||
+ | [ | ||
+ | { | ||
+ | "type" : | ||
+ | { | ||
+ | "push_cmt" : 123, | ||
+ | "attach" : 111, | ||
+ | "app_mid" : "123456abc" | ||
+ | } | ||
+ | }, | ||
+ | { | ||
+ | "type2" : | ||
+ | { | ||
+ | "app_xmid" : 123 | ||
+ | } | ||
+ | } | ||
+ | ], | ||
+ | "in_reply_to_screen_name" : "", | ||
+ | "geo" : null, | ||
+ | "user" : | ||
+ | { | ||
+ | "name" : "siegetest2", | ||
+ | "domain" : "", | ||
+ | "geo_enabled" : true, | ||
+ | "followers_count" : 0, | ||
+ | "statuses_count" : 2, | ||
+ | "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" : 4288367041, | ||
+ | "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; | ||
+ | |||
+ | 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 | 微博SDK开发包下载]] 处下载PHP SDK(支持OAuth验证之版本)<br> | ||
+ | 代码示例如下: | ||
+ | <pre> | ||
+ | //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"]); | |
− | + | </pre> | |
− | + | }} | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + |
2010年12月13日 (一) 14:47的版本
目录 |
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个字符,具体内容可以自定。 |
注意事项
{{{useAge}}}
返回结果
{{{result}}}
其他
{{{otherInfo}}},{"type2":{"app_xmid":123}}]'| result=
XML示例
<?xml version="1.0" encoding="UTF-8"?> <status> <created_at>Mon Dec 13 14:41:15 +0800 2010</created_at> <id>4288263839</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>38</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"> <type class="object"> <app_mid type="string">123456abc</app_mid> <attach type="number">111</attach> <push_cmt type="number">123</push_cmt> </type> </annotation> <annotation class="object"> <type2 class="object"> <app_xmid type="number">123</app_xmid> </type2> </annotation> </annotations> </status>
JSON示例
{ "created_at" : "Mon Dec 13 14:46:10 +0800 2010", "text" : "abc", "truncated" : false, "in_reply_to_status_id" : "", "annotations" : [ { "type" : { "push_cmt" : 123, "attach" : 111, "app_mid" : "123456abc" } }, { "type2" : { "app_xmid" : 123 } } ], "in_reply_to_screen_name" : "", "geo" : null, "user" : { "name" : "siegetest2", "domain" : "", "geo_enabled" : true, "followers_count" : 0, "statuses_count" : 2, "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" : 4288367041, "source" : "<a href=\"http://open.t.sina.com.cn\" rel=\"nofollow\">微博开放平台接口</a>" }|
useAge=
- 为防止重复提交,当用户发布的微博消息与上次成功发布的微博消息内容一样时,将返回400错误,给出错误提示:“40025:Error: repeated weibo text!“。
- 转发微博消息时接口的表现可参考statuses/repost|
otherInfo=
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"]);
}}