Account/update profile

跳转到: 导航, 搜索
(返回数据格式:)
 
(未显示6个用户的35个中间版本)
第1行: 第1行:
== account/update_profile ==
+
{{api_desc2|
自定义微薄页面的参数。只会修改参数更新项。
+
uri=account/update_profile|
 
+
desc=更新当前登录用户在新浪微博上的基本信息。|
Sets values that users are able to set under the "Account" tab of their settings page. Only the parameters specified will be updated.
+
format=XML/JSON|
 
+
httpMethod=POST|
=== URL地址: ===
+
needAuth=true|
http://api.t.sina.com.cn/account/update_profile.format
+
rateLimit=true|
+
params={{api_args_colspan|1=<div style="color:#ee3333">下列参数必选其一,多选不限。</div>}}
===Formats:===
+
{{api_args|name|false|string|昵称,不超过20个字符}}
xml, json
+
{{api_args|gender|false|string|性别, m 表示男性,f 表示女性。}}
+
{{api_args|province|false|int|省份代码,参考[[省份城市编码表]]}}
=== HTTP 请求方法: ===
+
{{api_args|city|false|int|城市代码,1000表示不指定具体城市。参考[[省份城市编码表]]}}
GET
+
{{api_args|description|false|string|个人描述。不超过70个汉字}}|
+
getParam=|
===是否需要认证: ===
+
postParam=-d "gender=m&name=openapi"|
true
+
result=
 
+
===XML示例===
===调用频率限制: ===
+
<pre>
false
+
 
+
===请求参数说明:===
+
必须有一下参数中的一个或多个,参数值为字符串. 进一步的限制,请参阅下面的各个参数描述.
+
* name. 可选参数.不超过20个汉字
+
* url. 可选参数. 不超过100个汉字 ,必须以"http://"开头
+
* location. 可选参数.不超过30个汉字 ,输入完整的所在地方信息
+
* description. 可选参数. 不超过160个汉字.
+
 
+
One or more of the following parameters must be present.  Each parameter's value should be a string.  See the individual parameter descriptions below for further constraints.
+
 
+
* name. Optional. Maximum of 20 characters.
+
* url. Optional. Maximum of 100 characters. Will be prepended with "http://" if not present.
+
* location. Optional. Maximum of 30 characters. The contents are not normalized or geocoded in any way.
+
* description. Optional. Maximum of 160 characters.
+
 
+
===返回数据格式:===
+
XML 格式样例(部分内容删减):
+
 
  <?xml version="1.0" encoding="UTF-8"?>
 
  <?xml version="1.0" encoding="UTF-8"?>
 
  <user>
 
  <user>
<id>1401881</id>
+
    <id>11075</id>
<name>Doug Williams</name>
+
    <screen_name>openapi</screen_name>
<screen_name>dougw</screen_name>
+
    <name>openapi</name>
<location>San Francisco, CA</location>
+
    <province>广东</province>
<description>Twitter API Support. Internet, greed, users, dougw and opportunities are my passions.</description>
+
    <city>广州</city>
<profile_image_url>http://s3.amazonaws.com/twitter_production/profile_images/59648642/avatar_normal.png</profile_image_url>
+
    <location>广东 广州</location>
<url>http://www.igudo.com</url>
+
    <description></description>
<protected>false</protected>
+
    <url></url>
<followers_count>1031</followers_count>
+
    <profile_image_url>http://portrait.sinaimg.cn/11075/50#.jpg</profile_image_url>
<profile_background_color>9ae4e8</profile_background_color>
+
    <domain></domain>
<profile_text_color>000000</profile_text_color>
+
    <gender></gender>
<profile_link_color>0000ff</profile_link_color>
+
    <followers_count>0</followers_count>
<profile_sidebar_fill_color>e0ff92</profile_sidebar_fill_color>
+
    <friends_count>0</friends_count>
<profile_sidebar_border_color>87bc44</profile_sidebar_border_color>
+
    <statuses_count>0</statuses_count>
<friends_count>293</friends_count>
+
    <favourites_count>0</favourites_count>
<created_at>Sun Mar 18 06:42:26 +0000 2007</created_at>
+
    <created_at>Thu Jan 01 08:00:00 +0800 1970</created_at>
<favourites_count>0</favourites_count>
+
    <following>false</following>
<utc_offset>-18000</utc_offset>
+
    <verified>false</verified>
<time_zone>Eastern Time (US & Canada)</time_zone>
+
    <geo_enabled>false</geo_enabled>
<profile_background_image_url>http://s3.amazonaws.com/twitter_production/profile_background_images/2752608/twitter_bg_grass.jpg</profile_background_image_url>
+
    <status>
<profile_background_tile>false</profile_background_tile>
+
      <created_at>Fri Dec 25 17:57:27 +0800 2009</created_at>
<statuses_count>3390</statuses_count>
+
      <id>19093</id>
<notifications>false</notifications>
+
      <text>测试</text>
<following>false</following>
+
      <source>
<verified>true</verified>
+
        <a id="0" href="http://t.sina.com.cn">Web</a>
<status>
+
      </source>
<created_at>Tue Apr 07 22:52:51 +0000 2009</created_at>
+
      <favorited>false</favorited>
<id>1472669360</id>
+
      <truncated>false</truncated>
<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>
+
      <geo/>
<source><a href="http://www.tweetdeck.com/">TweetDeck</a></source>
+
      <in_reply_to_status_id></in_reply_to_status_id>
<truncated>false</truncated>
+
      <in_reply_to_user_id></in_reply_to_user_id>
<in_reply_to_status_id></in_reply_to_status_id>
+
      <in_reply_to_screen_name></in_reply_to_screen_name>
<in_reply_to_user_id></in_reply_to_user_id>
+
    </status>
<favorited>false</favorited>
+
<in_reply_to_screen_name></in_reply_to_screen_name>
+
</status>
+
 
  </user>
 
  </user>
 
+
</pre>
===调用例子: ===
+
===JSON示例===
cURL (about cURL):
+
<pre>
 
+
  {
curl -u user:password -d "url=http://www.igudo.com" http://api.t.sina.com.cn/account/update_profile.xml
+
    "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