Users/show

跳转到: 导航, 搜索
(返回)
 
(未显示8个用户的33个中间版本)
第1行: 第1行:
== users/show ==
+
{{api_desc2|
按用户UID或昵称返回用户资料,同时也将返回用户的最新发布的微博。
+
uri=users/show|
 
+
desc=按用户ID或昵称返回用户资料以及用户的最新发布的一条微博消息。 |
=== URL===
+
format=XML/JSON|
curl http://api.t.sina.com.cn/users/show.format
+
httpMethod=GET|
 +
needAuth=true|
 +
rateLimit=true|
 +
params={{api_args|:id|false|int64/string|用户ID(int64)或者昵称(string)。该参数为一个REST风格参数。调用示例见注意事项}}
 +
{{api_args|user_id|false|int64|用户ID,主要是用来区分用户ID跟微博昵称。当微博昵称为数字导致和用户ID产生歧义,特别是当微博昵称和用户ID一样的时候,建议使用该参数}}
 +
{{api_args|screen_name|false|string|微博昵称,主要是用来区分用户UID跟微博昵称,当二者一样而产生歧义的时候,建议使用该参数}}
 +
{{api_args_colspan|1=<font style="color:#ee3333">:id、user_id、screen_name这三个参数三者至少要提供一个</font>}}|
 +
getParam=&user_id=11051|
 +
postParam=|
 +
result=
 +
===XML示例===
 +
<pre>
 +
<?xml version="1.0" encoding="UTF-8"?>
 +
<user>
 +
  <id>11051</id>
 +
  <screen_name>微博开放平台</screen_name>
 +
  <name>微博开放平台</name>
 +
  <province>11</province>
 +
  <city>8</city>
 +
  <location>北京 海淀区</location>
 +
  <description>新浪微博开放平台市场推广官方账号,如有技术问题,请@微博API或者发私信给微博API</description>
 +
  <url>http://open.t.sina.com.cn/</url>
 +
  <profile_image_url>http://tp4.sinaimg.cn/11051/50/1280283165/1</profile_image_url>
 +
  <domain>openapi</domain>
 +
  <gender>m</gender>
 +
  <followers_count>13247</followers_count>
 +
  <friends_count>5</friends_count>
 +
  <statuses_count>158</statuses_count>
 +
  <favourites_count>0</favourites_count>
 +
  <created_at>Wed Jan 20 00:00:00 +0800 2010</created_at>
 +
  <following>false</following>
 +
  <verified>true</verified>
 +
  <allow_all_act_msg>true</allow_all_act_msg>
 +
  <geo_enabled>true</geo_enabled>
 +
  <status>
 +
    <created_at>Mon Nov 29 16:08:43 +0800 2010</created_at>
 +
    <id>3958728723</id>
 +
    <text>各位开发者,我们的论坛上线啦~http://sinaurl.cn/h4FWc7 欢迎大家的参与~另外,关于技术相关的问题,可以在论坛上提出,也可以@微博API 这个官方技术支持账号哦~感谢大家对开放平台的支持~[呵呵]</text>
 +
    <source>
 +
      <a href="http://t.sina.com.cn">新浪微博</a>
 +
    </source>
 +
    <favorited>false</favorited>
 +
    <truncated>false</truncated>
 +
    <geo/>
 +
    <in_reply_to_status_id/>
 +
    <in_reply_to_user_id/>
 +
    <in_reply_to_screen_name/>
 +
  </status>
 +
</user>
 +
</pre>
 +
===JSON示例===
 +
<pre>
 +
{
 +
    "name" : "微博开放平台",
 +
    "domain" : "openapi",
 +
    "geo_enabled" : true,
 +
    "followers_count" : 13247,
 +
    "statuses_count" : 158,
 +
    "favourites_count" : 0,
 +
    "city" : "8",
 +
    "description" : "新浪微博开放平台市场推广官方账号,如有技术问题,请@微博API或者发私信给微博API",
 +
    "verified" : true,
 +
    "status" :
 +
    {
 +
        "created_at" : "Mon Nov 29 16:08:43 +0800 2010",
 +
        "text" : "各位开发者,我们的论坛上线啦~http://sinaurl.cn/h4FWc7 欢迎大家的参与~另外,关于技术相关的问题,可以在论坛上提出,也可以@微博API 这个官方技术支持账号哦~感谢大家对开放平台的支持~[呵呵]",
 +
        "truncated" : false,
 +
        "in_reply_to_status_id" : "",
 +
        "in_reply_to_screen_name" : "",
 +
        "geo" : null,
 +
        "favorited" : false,
 +
        "in_reply_to_user_id" : "",
 +
        "id" : 3958728723,
 +
        "source" : "<a href=\"http://t.sina.com.cn\" rel=\"nofollow\">新浪微博</a>"
 +
    },
 +
    "id" : 11051,
 +
    "gender" : "m",
 +
    "friends_count" : 5,
 +
    "screen_name" : "微博开放平台",
 +
    "allow_all_act_msg" : true,
 +
    "following" : false,
 +
    "url" : "http://open.t.sina.com.cn/",
 +
    "profile_image_url" : "http://tp4.sinaimg.cn/11051/50/1280283165/1",
 +
    "created_at" : "Wed Jan 20 00:00:00 +0800 2010",
 +
    "province" : "11",
 +
    "location" : "北京 海淀区"
 +
}
 +
</pre>
 +
{{param_user}}
 +
{{param_status}}|
 +
useAge=
 +
* :id为REST风格的参数,使用该参数的URL为:<br/> http://api.t.sina.com.cn/users/show/:id.format <br/> 使用示例如下:<br/> http://api.t.sina.com.cn/users/show/11051.xml?source=appkey<br/>http://api.t.sina.com.cn/users/show/timyang.json?source=appkey
 +
* 若用户ID不存在,或者微博昵称不存在,则返回400错误,提示:"40023:Error: User does not exists!"。
 +
* 若三个参数均未提供,则返回400错误。系统认为提交了一个未知的用户ID,提示:"40023:Error: User does not exists!"。
 +
* 为了保护用户隐私,只有用户设置了公开或对粉丝设置了公开的数据才会返回。|
 +
otherInfo=
 +
===Java示例===
 +
请从 [[SDK | 微博SDK开发包下载]] 下载Java SDK<br>
 +
代码示例如下:
 +
package weibo4j.examples;
 
   
 
   
=== 格式===
+
import weibo4j.User;
xml, json
+
import weibo4j.Weibo;
 +
import weibo4j.WeiboException;
 
   
 
   
=== HTTP请求方式===
+
public class GetUserInfo {
GET
+
 
   
 
   
=== 是否需要身份验证===
+
/**
false
+
* 根据用户ID获取用户资料(授权用户)
+
* @param args
=== 请求数限制===
+
*/
1 call per request
+
public static void main(String[] args) {
 
+
System.setProperty("weibo4j.oauth.consumerKey", Weibo.CONSUMER_KEY);
=== 请求参数===
+
    System.setProperty("weibo4j.oauth.consumerSecret", Weibo.CONSUMER_SECRET);
* id. 用户UID或用户帐号。
+
try {
o Example: http://api.t.sina.com.cn/users/show/12345.json or http://api.t.sina.com.cn/users/show/bob.xml
+
User user = getWeibo(true,args).showUser(args[2]);
* user_id. 指定用户UID,主要是用来区分用户UID跟用户账号一样,产生歧义的时候,特别是在用户账号为数字导致和用户Uid发生歧义。 
+
System.out.println(user.toString());
o Example: http://api.t.sina.com.cn/users/show.xml?user_id=1401881
+
} catch (WeiboException e) {
* screen_name. 指定用户昵称,主要是用来区分用户UID跟用户账号一样,产生歧义的时候。
+
e.printStackTrace();
o Example: http://api.t.sina.com.cn/users/show.xml?screen_name=101010
+
}
 
+
}
=== 使用说明===
+
* 为了保护用户隐私,只有用户设置了公开或对粉丝设置了公开的数据才会返回。
+
private static Weibo getWeibo(boolean isOauth,String[] args) {
 
+
Weibo weibo = new Weibo();
=== 返回 ===
+
if(isOauth) {//oauth验证方式 args[0]:访问的token;args[1]:访问的密匙
XML示例:
+
weibo.setToken(args[0], args[1]);
<?xml version="1.0" encoding="UTF-8"?>
+
}else {//用户登录方式
  <user>
+
    weibo.setUserId(args[0]);//用户名/ID
    <id>11075</id>
+
    weibo.setPassword(args[1]);//密码
    <screen_name>name_11075</screen_name>
+
}
    <name>name_11075</name>
+
return weibo;
    <province>0</province>
+
}
    <city>0</city>
+
}
    <location></location>
+
===PHP示例===
    <description></description>
+
请从 [[SDK | 微博SDK开发包下载]] 处下载PHP SDK(支持OAuth验证之版本)<br>  
    <profile_image_url>http://tp4.sinaimg.cn/11075/50/0</profile_image_url>
+
代码示例如下:
    <domain>11075</domain>
+
<pre>
    <gender></gender>
+
//users/show
    <email></email>
+
//根据用户ID获取用户资料(授权用户)
    <qq>4102</qq>
+
$c = new WeiboClient( WB_AKEY ,  
    <msn>msn_4102</msn>
+
                      WB_SKEY ,  
    <followers_count>28</followers_count>
+
                      $_SESSION['last_key']['oauth_token'] ,  
    <friends_count>50</friends_count>
+
                      $_SESSION['last_key']['oauth_token_secret']  );
    <statuses_count>29</statuses_count>
+
//用户ID
    <favourites_count>0</favourites_count>
+
$u_id = "u_id";
    <created_at>Thu Jan 01 08:00:00 +0800 1970</created_at>
+
$msg = $c->show_user($u_id);
    <following>false</following>
+
if ($msg === false || $msg === null){
    <verified>true</verified>
+
echo "Error occured";
    <geo_enabled>false</geo_enabled>
+
return false;
    <status>
+
}
      <created_at>Thu Jan 07 17:36:07 +0800 2010</created_at>
+
if (isset($msg['error_code']) && isset($msg['error'])){
      <id>142309</id>
+
echo ('Error_code: '.$msg['error_code'].';  Error: '.$msg['error'] );
      <text>要查询的微博ID</text>
+
return false;
      <source>
+
}
        <a id="0" href="http://t.sina.com.cn">Web</a>
+
echo($msg['id'].' : '.$msg['name'].'  '.$msg['created_at']);
      </source>
+
</pre>
      <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":"name_11075",
+
    "name":"name_11075",
+
    "province":"0",
+
    "city":"0",
+
    "location":"",
+
    "description":"",
+
    "profile_image_url":"http://tp4.sinaimg.cn/11075/50/0",
+
    "domain":"11075",
+
    "email":"",
+
    "qq":"4102",
+
    "msn":"msn_4102",
+
    "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":"要查询的微博ID",
+
            "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,
+
            "apiState":3}
+
  }
+
 
+
=== 使用示例===
+
cURL:
+
 
+
curl http://api.t.sina.com.cn/users/show.xml?screen_name=timyang
+

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

目录

users/show

按用户ID或昵称返回用户资料以及用户的最新发布的一条微博消息。

URL

http://api.t.sina.com.cn/users/show.(json%7Cxml)

支持格式

XML/JSON

HTTP请求方式

GET

是否需要登录

true
关于授权机制,参见授权机制声明

请求数限制

true
关于请求数限制,参见接口访问权限说明

请求参数

  必选 类型及范围 说明
source true string 申请应用时分配的AppKey,调用接口时候代表应用的唯一身份。(采用OAuth授权方式不需要此参数)
:id false int64/string 用户ID(int64)或者昵称(string)。该参数为一个REST风格参数。调用示例见注意事项
user_id false int64 用户ID,主要是用来区分用户ID跟微博昵称。当微博昵称为数字导致和用户ID产生歧义,特别是当微博昵称和用户ID一样的时候,建议使用该参数
screen_name false string 微博昵称,主要是用来区分用户UID跟微博昵称,当二者一样而产生歧义的时候,建议使用该参数
:id、user_id、screen_name这三个参数三者至少要提供一个

注意事项

返回结果

XML示例

<?xml version="1.0" encoding="UTF-8"?>
<user>
  <id>11051</id>
  <screen_name>微博开放平台</screen_name>
  <name>微博开放平台</name>
  <province>11</province>
  <city>8</city>
  <location>北京 海淀区</location>
  <description>新浪微博开放平台市场推广官方账号,如有技术问题,请@微博API或者发私信给微博API</description>
  <url>http://open.t.sina.com.cn/</url>
  <profile_image_url>http://tp4.sinaimg.cn/11051/50/1280283165/1</profile_image_url>
  <domain>openapi</domain>
  <gender>m</gender>
  <followers_count>13247</followers_count>
  <friends_count>5</friends_count>
  <statuses_count>158</statuses_count>
  <favourites_count>0</favourites_count>
  <created_at>Wed Jan 20 00:00:00 +0800 2010</created_at>
  <following>false</following>
  <verified>true</verified>
  <allow_all_act_msg>true</allow_all_act_msg>
  <geo_enabled>true</geo_enabled>
  <status>
    <created_at>Mon Nov 29 16:08:43 +0800 2010</created_at>
    <id>3958728723</id>
    <text>各位开发者,我们的论坛上线啦~http://sinaurl.cn/h4FWc7 欢迎大家的参与~另外,关于技术相关的问题,可以在论坛上提出,也可以@微博API 这个官方技术支持账号哦~感谢大家对开放平台的支持~[呵呵]</text>
    <source>
      <a href="http://t.sina.com.cn">新浪微博</a>
    </source>
    <favorited>false</favorited>
    <truncated>false</truncated>
    <geo/>
    <in_reply_to_status_id/>
    <in_reply_to_user_id/>
    <in_reply_to_screen_name/>
  </status>
</user>

JSON示例

{
    "name" : "微博开放平台",
    "domain" : "openapi",
    "geo_enabled" : true,
    "followers_count" : 13247,
    "statuses_count" : 158,
    "favourites_count" : 0,
    "city" : "8",
    "description" : "新浪微博开放平台市场推广官方账号,如有技术问题,请@微博API或者发私信给微博API",
    "verified" : true,
    "status" : 
    {
        "created_at" : "Mon Nov 29 16:08:43 +0800 2010",
        "text" : "各位开发者,我们的论坛上线啦~http://sinaurl.cn/h4FWc7 欢迎大家的参与~另外,关于技术相关的问题,可以在论坛上提出,也可以@微博API 这个官方技术支持账号哦~感谢大家对开放平台的支持~[呵呵]",
        "truncated" : false,
        "in_reply_to_status_id" : "",
        "in_reply_to_screen_name" : "",
        "geo" : null,
        "favorited" : false,
        "in_reply_to_user_id" : "",
        "id" : 3958728723,
        "source" : "<a href=\"http://t.sina.com.cn\" rel=\"nofollow\">新浪微博</a>"
    },
    "id" : 11051,
    "gender" : "m",
    "friends_count" : 5,
    "screen_name" : "微博开放平台",
    "allow_all_act_msg" : true,
    "following" : false,
    "url" : "http://open.t.sina.com.cn/",
    "profile_image_url" : "http://tp4.sinaimg.cn/11051/50/1280283165/1",
    "created_at" : "Wed Jan 20 00:00:00 +0800 2010",
    "province" : "11",
    "location" : "北京 海淀区"
}

字段说明 - user

  • id: 用户UID
  • screen_name: 微博昵称
  • name: 友好显示名称,同微博昵称
  • province: 省份编码(参考省份编码表)
  • city: 城市编码(参考城市编码表)
  • location:地址
  • description: 个人描述
  • url: 用户博客地址
  • profile_image_url: 自定义图像
  • domain: 用户个性化URL
  • gender: 性别,m--男,f--女,n--未知
  • followers_count: 粉丝数
  • friends_count: 关注数
  • statuses_count: 微博数
  • favourites_count: 收藏数
  • created_at: 创建时间
  • following: 是否已关注(此特性暂不支持)
  • verified: 加V标示,是否微博认证用户

字段说明 - status

  • created_at: 创建时间
  • id: 微博ID
  • text: 微博信息内容
  • source: 微博来源
  • favorited: 是否已收藏
  • truncated: 是否被截断
  • in_reply_to_status_id: 回复ID
  • in_reply_to_user_id: 回复人UID
  • in_reply_to_screen_name: 回复人昵称
  • thumbnail_pic: 缩略图
  • bmiddle_pic: 中型图片
  • original_pic:原始图片
  • user: 作者信息
  • retweeted_status: 转发的博文,内容为status,如果不是转发,则没有此字段

其他

Java示例

请从 微博SDK开发包下载 下载Java SDK
代码示例如下:

package weibo4j.examples;

import weibo4j.User;
import weibo4j.Weibo;
import weibo4j.WeiboException; 

public class GetUserInfo {

	/**
	 * 根据用户ID获取用户资料(授权用户) 
	 * @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 {
			User user = getWeibo(true,args).showUser(args[2]);
			System.out.println(user.toString());
		} catch (WeiboException 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验证之版本)
代码示例如下:

//users/show
//根据用户ID获取用户资料(授权用户)
$c = new WeiboClient( WB_AKEY , 
                      WB_SKEY , 
                      $_SESSION['last_key']['oauth_token'] , 
                      $_SESSION['last_key']['oauth_token_secret']  );
//用户ID
$u_id = "u_id";
$msg = $c->show_user($u_id);
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['name'].'  '.$msg['created_at']);
文档更新时间: 2012-09-24