sina微博js开发日记

1 篇文章 0 订阅
1 篇文章 0 订阅
简单例子
<html>
<head>
<title>js微博</title>
<script src=" http://tjs.sjs.sinajs.cn/open/api/js/wb.js?appkey=4079112329" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
</head>
<body>
<div position="fixed"><button>登录</button>  </div>
<div id="content"></div>
<script>
function login()
{
  if(WB2.checkLogin()) //用户是否否登录
  {
       //获取用户微博信息
	   $("button").text("退出");
       getStatus();
  }
  else
  {
      WB2.login(
	 	function()
		{
			$("button").text("退出");
		  getStatus();
		}
	  );
   
  }
 }
function logout()
{
	WB2.logout(
		function()
		{
			$("button").text("登录");
			$("#content>div").remove();
		}
	);
}
  //获取当前登录用户及其所关注用户的最新微博消息
function getStatus()
{
       var url="/statuses/friends_timeline.json";
       WB2.anyWhere(
          function(W)
          {
              W.parseCMD(
                url,
                function(result,b)
                {
                    for(i=0;i<result.length;i++)
                    {
                        username=result[i].user.name;//微博作者
						userimg=result[i].user.profile_image_url;//微博作者头像
                        date=result[i].created_at;  //微博发布时间        
                        id= result[i].id;//微博id
						text=result[i].text;//微博内容
						img=result[i].thumbnail_pic;//微博配图
						if(result[i].retweeted_status!=null)
						{
							username1=result[i].retweeted_status.user.name;
							text=text+"@"+username1+"<br>"+result[i].retweeted_status.text;//转发内容
							img=result[i].retweeted_status.thumbnail_pic;//微博配图,小图
						}
						if(img!=null)
						{
							text=text+"<br><img src=\""+img+"\" />";
						}						
                     	
						message="<img src=\""+userimg+"\"> "+username+":"+text;
                        $("#content").append("<div>"+message+"</div>");
						
                    }
                   
                }
              );
          }
       );
 }
$("button").click(
		function()
		{
			if($(this).text()=="登录")
			{
				login();
			}
			if($(this).text()=="退出")
			{
				logout();
			}
  		}
 ) 
 

</script>
</body>
</html>



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值