JS进阶篇--ajax请求微博账号的信息,粉丝数、微博数

调用的基本原理很简单,就是我们将账号的信息(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('调用数据不存在!'); } } }); });

参考网址:http://open.weibo.com/wiki/%E...

新浪微博关注按钮API:http://open.weibo.com/widget/...

你可能感兴趣的:(新浪微博)