调用的基本原理很简单,就是我们将账号的信息(id,appkey,昵称)通过GET方式提交给新浪开放平台,然后获取到授权,同时将数据以json的格式返回。
$(function(){
var html="";
$.ajax({
url:'https://api.weibo.com/2/users/show.json?source=XXX&uid=XXX', //参数与v1接口相似
type:'GET',
dataType:'jsonp', //[重要],默认是支持jsonp格式数据的返回可解决跨域问题;
cache:false,
success:function(msg){
//获取返回信息
if(msg!='' && msg!=null)
{
html += "
- ";
html += "
ID:"+msg.data.id+"";html += "
昵称:"+msg.data.screen_name+"";html += "
粉丝数:"+msg.data.followers_count+"";html += "
关注:"+msg.data.friends_count+"";html += "
微博数:"+msg.data.statuses_count+"";html +="
";document.write(html);
}
else
{
alert('调用数据不存在!');
}
}
});
});