转载http://www.cnblogs.com/lhj588/archive/2011/06/02/2067575.html
转载地址2:http://voodeng.com/blog/2012/09/03/sina-weibo-api-on-jquery/
<script src=" http://tjs.sjs.sinajs.cn/open/api/js/wb.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="/js/jquery-1.4.3.min.js"></script>
注意事项(注意数据类型,以及appkey的申请);
appKey:<input id="txtAppKey" value="245712105" />
用户ID:<input id="txtUserId" value="" />
微博昵称:<input id="txtScrName" value="微博账号ID" />
<button type="button" id="btnGetUserDat">获取用户信息</button>
<div id="divUserData"> </div>
<script language="javascript" type="text/javascript">
$(function () {
$("#btnGetUserDat").click(function () {
GetFriends($("#txtAppKey").val(), $("#txtUserId").val(), $("#txtScrName").val());
});
});
//验证是否为空
function IsNullOrEmpty(dataStr) {
if (dataStr == null || dataStr == "" || dataStr == undefined || dataStr == "undefined") {
return true; }
else {
return false; } }
//获取API接口数据
function GetFriends(appkey, userid_id, screen_name) {
// var url = "http://api.t.sina.com.cn/users/show.json?source=" + appkey + "&user_id=" + userid_id;
$("#divUserData").empty();
if (IsNullOrEmpty(appkey)) {
alert("很抱歉,appkey不能为空。");
return; }
if (IsNullOrEmpty(userid_id) && IsNullOrEmpty(screen_name)) {
alert("很抱歉,用户ID和微博昵称最少填写一个。");
return; }
var urlData = "source=" + appkey;
if (!IsNullOrEmpty(userid_id)) {
urlData += "&user_id=" + userid_id
} else if (!IsNullOrEmpty(screen_name)) {
urlData += "&screen_name=" + screen_name;
}
var url = "http://api.t.sina.com.cn/users/show.json?" + urlData;
// jQuery
$.ajax({
url: url, // url,
type: "GET",
dataType: "jsonp",
cache: false,
success: function (data) {
alert(data.data);
inf=data.data;
if (data.data != null && data.data != null && data.data != undefined) {
var msg = data.data;
var sex = "未知";
if (data.data.gender == "m") {
sex = "男";
}
else if (data.data.gender == "f") {
sex = "女";
}
var html = "<ul>"+ "<li>微博昵称:" + data.data.screen_name + "</li>"
+ "<li>同微博昵称:" + data.data.name + "</li>"
+ "<li>省份编码:" + data.data.province + "</li>"
+ "<li>城市编码:" + data.data.city + "</li>"
+ "<li>地址:" + data.data.location + "</li>"
+ "<li>个人描述:" + data.data.description + "</li>"
+ "<li>用户博客地址:" + data.data.url + "</li>"
+ "<li>性别:" + sex + "</li>"
+ "<li>微博数:" + data.data.statuses_count + "</li>"
+ "<li>收藏数:" + data.data.favourites_count + "</li>"
+ "<li>创建时间:" + data.data.created_at + "</li>"
+ "</ul>";
$("#divUserData").html(html);
} else {
$("#divUserData").html("用户不存在");
}
}
});
} </script>