Account/update profile
(→返回数据格式:) |
|||
(未显示6个用户的35个中间版本) | |||
第1行: | 第1行: | ||
− | + | {{api_desc2| | |
− | + | uri=account/update_profile| | |
− | + | desc=更新当前登录用户在新浪微博上的基本信息。| | |
− | + | format=XML/JSON| | |
− | + | httpMethod=POST| | |
− | = | + | needAuth=true| |
− | + | rateLimit=true| | |
− | + | params={{api_args_colspan|1=<div style="color:#ee3333">下列参数必选其一,多选不限。</div>}} | |
− | = | + | {{api_args|name|false|string|昵称,不超过20个字符}} |
− | + | {{api_args|gender|false|string|性别, m 表示男性,f 表示女性。}} | |
− | + | {{api_args|province|false|int|省份代码,参考[[省份城市编码表]]}} | |
− | = | + | {{api_args|city|false|int|城市代码,1000表示不指定具体城市。参考[[省份城市编码表]]}} |
− | + | {{api_args|description|false|string|个人描述。不超过70个汉字}}| | |
− | + | getParam=| | |
− | = | + | postParam=-d "gender=m&name=openapi"| |
− | true | + | result= |
− | + | ===XML示例=== | |
− | === | + | <pre> |
− | false | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | === | + | |
− | + | ||
<?xml version="1.0" encoding="UTF-8"?> | <?xml version="1.0" encoding="UTF-8"?> | ||
<user> | <user> | ||
− | + | <id>11075</id> | |
− | + | <screen_name>openapi</screen_name> | |
− | + | <name>openapi</name> | |
− | + | <province>广东</province> | |
− | + | <city>广州</city> | |
− | + | <location>广东 广州</location> | |
− | + | <description></description> | |
− | + | <url></url> | |
− | + | <profile_image_url>http://portrait.sinaimg.cn/11075/50#.jpg</profile_image_url> | |
− | + | <domain></domain> | |
− | + | <gender></gender> | |
− | + | <followers_count>0</followers_count> | |
− | + | <friends_count>0</friends_count> | |
− | + | <statuses_count>0</statuses_count> | |
− | + | <favourites_count>0</favourites_count> | |
− | + | <created_at>Thu Jan 01 08:00:00 +0800 1970</created_at> | |
− | + | <following>false</following> | |
− | + | <verified>false</verified> | |
− | + | <geo_enabled>false</geo_enabled> | |
− | + | <status> | |
− | + | <created_at>Fri Dec 25 17:57:27 +0800 2009</created_at> | |
− | + | <id>19093</id> | |
− | + | <text>测试</text> | |
− | + | <source> | |
− | + | <a id="0" href="http://t.sina.com.cn">Web</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> | |
− | + | </status> | |
− | + | ||
− | + | ||
− | + | ||
</user> | </user> | ||
− | + | </pre> | |
− | === | + | ===JSON示例=== |
− | + | <pre> | |
− | + | { | |
− | + | "id":11075, | |
+ | "screen_name":"openapi", | ||
+ | "name":"openapi", | ||
+ | "province":"0", | ||
+ | "city":"0", | ||
+ | "location":"", | ||
+ | "description":"", | ||
+ | "url":"", | ||
+ | "profile_image_url":"http://tp4.sinaimg.cn/11075/50/0", | ||
+ | "domain":"11075", | ||
+ | "followers_count":28, | ||
+ | "friends_count":50, | ||
+ | "statuses_count":29, | ||
+ | "favourites_count":0, | ||
+ | "created_at":"Thu Jan 01 08:00:00 +0800 1970", | ||
+ | "following":false, | ||
+ | "geo_enabled":false, | ||
+ | "verified":true, | ||
+ | "status": | ||
+ | {"created_at":"Thu Jan 07 17:36:07 +0800 2010", | ||
+ | "id":142309, | ||
+ | "text":"测试", | ||
+ | "source":"<a id=\"0\" href=\"http://t.sina.com.cn/\" rel=\"nofollow\">Web</a>", | ||
+ | "favorited":false, | ||
+ | "truncated":false, | ||
+ | "in_reply_to_status_id":"", | ||
+ | "in_reply_to_user_id":"", | ||
+ | "in_reply_to_screen_name":"", | ||
+ | "geo":null} | ||
+ | } | ||
+ | </pre>| | ||
+ | useAge= | ||
+ | * 提交成功后,只有参与提交的参数所对应的信息项会被更新。未参与提交的信息项将保持原值不变。 | ||
+ | * 例如:只提交name和gender参数,则只对用户昵称和性别进行更新,用户的省份、城市以及个人描述保持原值不变。| | ||
+ | otherInfo= | ||
+ | ===Java示例=== | ||
+ | 请从 [[SDK | 微博SDK开发包下载]] 下载Java SDK<br> | ||
+ | 代码示例如下: | ||
+ | package weibo4j.examples; | ||
+ | |||
+ | import weibo4j.User; | ||
+ | import weibo4j.Weibo; | ||
+ | |||
+ | public class OAuthUpdateProfile { | ||
+ | |||
+ | /** | ||
+ | * Usage: java -DWeibo4j.oauth.consumerKey=[consumer key] | ||
+ | * -DWeibo4j.oauth.consumerSecret=[consumer secret] | ||
+ | * Weibo4j.examples.OAuthUpdateProfile [accessToken] [accessSecret] | ||
+ | * [imageFilePath] | ||
+ | * | ||
+ | * @param args | ||
+ | * message | ||
+ | */ | ||
+ | public static void main(String[] args) { | ||
+ | try { | ||
+ | if (args.length < 3) { | ||
+ | System.out.println( | ||
+ | "Usage: java weibo4j.examples.OAuthUpdateProfile token tokenSecret filePath"); | ||
+ | System.exit( -1); | ||
+ | } | ||
+ | |||
+ | System.setProperty("weibo4j.oauth.consumerKey", Weibo.CONSUMER_KEY); | ||
+ | System.setProperty("weibo4j.oauth.consumerSecret", Weibo.CONSUMER_SECRET); | ||
+ | |||
+ | Weibo weibo = new Weibo(); | ||
+ | |||
+ | /* | ||
+ | * 此处需要填写AccessToken的key和Secret,可以从OAuthUpdate的执行结果中拷贝过来 | ||
+ | */ | ||
+ | weibo.setToken(args[0], args[1]); | ||
+ | try { | ||
+ | //args[2]:昵称;args[3]:email;args[4]:头像地址;args[5]:地区;args[6]:描述 | ||
+ | User user = weibo.updateProfile(args[2],args[3],args[4],args[5],args[6]); | ||
+ | System.out.println(user.toString()); | ||
+ | |||
+ | } catch (Exception e1) { | ||
+ | e1.printStackTrace(); | ||
+ | } | ||
+ | } catch (Exception ioe) { | ||
+ | System.out.println("Failed to read the system input."); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | ===PHP示例=== | ||
+ | 请从 [[SDK | 微博SDK开发包下载]] 处下载PHP SDK(支持OAuth验证之版本)<br> | ||
+ | 代码示例如下: | ||
+ | <pre> | ||
+ | //account/update_profile | ||
+ | $c = new WeiboClient( WB_AKEY , | ||
+ | WB_SKEY , | ||
+ | $_SESSION['last_key']['oauth_token'] , | ||
+ | $_SESSION['last_key']['oauth_token_secret'] ); | ||
+ | //name you want to change to | ||
+ | $name = 'name'; | ||
+ | //gender you want to change to | ||
+ | $gender = 'f'; | ||
+ | $param = array(); | ||
+ | $param['name'] = $name; | ||
+ | $param['gender']= $gender; | ||
+ | $msg = $c->oauth->post('http://api.t.sina.com.cn/account/update_profile.json',$param); | ||
+ | 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 (isset($msg['name'])){ | ||
+ | echo($msg['name']); | ||
+ | } | ||
+ | </pre> | ||
+ | }} |
2011年3月31日 (四) 15:36的最后版本
目录 |
account/update_profile
更新当前登录用户在新浪微博上的基本信息。
URL
http://api.t.sina.com.cn/account/update_profile.(json%7Cxml)
支持格式
XML/JSON
HTTP请求方式
POST
是否需要登录
true
关于授权机制,参见授权机制声明
请求数限制
true
关于请求数限制,参见接口访问权限说明
请求参数
必选 | 类型及范围 | 说明 | |
---|---|---|---|
source | true | string | 申请应用时分配的AppKey,调用接口时候代表应用的唯一身份。(采用OAuth授权方式不需要此参数) |
下列参数必选其一,多选不限。
| |||
name | false | string | 昵称,不超过20个字符 |
gender | false | string | 性别, m 表示男性,f 表示女性。 |
province | false | int | 省份代码,参考省份城市编码表 |
city | false | int | 城市代码,1000表示不指定具体城市。参考省份城市编码表 |
description | false | string | 个人描述。不超过70个汉字 |
注意事项
- 提交成功后,只有参与提交的参数所对应的信息项会被更新。未参与提交的信息项将保持原值不变。
- 例如:只提交name和gender参数,则只对用户昵称和性别进行更新,用户的省份、城市以及个人描述保持原值不变。
返回结果
XML示例
<?xml version="1.0" encoding="UTF-8"?> <user> <id>11075</id> <screen_name>openapi</screen_name> <name>openapi</name> <province>广东</province> <city>广州</city> <location>广东 广州</location> <description></description> <url></url> <profile_image_url>http://portrait.sinaimg.cn/11075/50#.jpg</profile_image_url> <domain></domain> <gender></gender> <followers_count>0</followers_count> <friends_count>0</friends_count> <statuses_count>0</statuses_count> <favourites_count>0</favourites_count> <created_at>Thu Jan 01 08:00:00 +0800 1970</created_at> <following>false</following> <verified>false</verified> <geo_enabled>false</geo_enabled> <status> <created_at>Fri Dec 25 17:57:27 +0800 2009</created_at> <id>19093</id> <text>测试</text> <source> <a id="0" href="http://t.sina.com.cn">Web</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> </status> </user>
JSON示例
{ "id":11075, "screen_name":"openapi", "name":"openapi", "province":"0", "city":"0", "location":"", "description":"", "url":"", "profile_image_url":"http://tp4.sinaimg.cn/11075/50/0", "domain":"11075", "followers_count":28, "friends_count":50, "statuses_count":29, "favourites_count":0, "created_at":"Thu Jan 01 08:00:00 +0800 1970", "following":false, "geo_enabled":false, "verified":true, "status": {"created_at":"Thu Jan 07 17:36:07 +0800 2010", "id":142309, "text":"测试", "source":"<a id=\"0\" href=\"http://t.sina.com.cn/\" rel=\"nofollow\">Web</a>", "favorited":false, "truncated":false, "in_reply_to_status_id":"", "in_reply_to_user_id":"", "in_reply_to_screen_name":"", "geo":null} }
其他
Java示例
请从 微博SDK开发包下载 下载Java SDK
代码示例如下:
package weibo4j.examples; import weibo4j.User; import weibo4j.Weibo; public class OAuthUpdateProfile { /** * Usage: java -DWeibo4j.oauth.consumerKey=[consumer key] * -DWeibo4j.oauth.consumerSecret=[consumer secret] * Weibo4j.examples.OAuthUpdateProfile [accessToken] [accessSecret] * [imageFilePath] * * @param args * message */ public static void main(String[] args) { try { if (args.length < 3) { System.out.println( "Usage: java weibo4j.examples.OAuthUpdateProfile token tokenSecret filePath"); System.exit( -1); } System.setProperty("weibo4j.oauth.consumerKey", Weibo.CONSUMER_KEY); System.setProperty("weibo4j.oauth.consumerSecret", Weibo.CONSUMER_SECRET); Weibo weibo = new Weibo(); /* * 此处需要填写AccessToken的key和Secret,可以从OAuthUpdate的执行结果中拷贝过来 */ weibo.setToken(args[0], args[1]); try { //args[2]:昵称;args[3]:email;args[4]:头像地址;args[5]:地区;args[6]:描述 User user = weibo.updateProfile(args[2],args[3],args[4],args[5],args[6]); System.out.println(user.toString()); } catch (Exception e1) { e1.printStackTrace(); } } catch (Exception ioe) { System.out.println("Failed to read the system input."); } } }
PHP示例
请从 微博SDK开发包下载 处下载PHP SDK(支持OAuth验证之版本)
代码示例如下:
//account/update_profile $c = new WeiboClient( WB_AKEY , WB_SKEY , $_SESSION['last_key']['oauth_token'] , $_SESSION['last_key']['oauth_token_secret'] ); //name you want to change to $name = 'name'; //gender you want to change to $gender = 'f'; $param = array(); $param['name'] = $name; $param['gender']= $gender; $msg = $c->oauth->post('http://api.t.sina.com.cn/account/update_profile.json',$param); 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 (isset($msg['name'])){ echo($msg['name']); }
文档更新时间: 2011-03-31