测试微博API引用页面 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>测试</title> <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /> </head> <body> <div id="weibocon"></div> <script src="weiboapi.js"></script> <script> window.onload = weibo; var wb = new weibo(); wb.init( null, "img",//参数说明:text-文本微博;img-选择图片发微博;trend-获取话题列表 { topic:encodeURI("装修"),//当第2个参数为trend时起作用 count:10, length:30, zturl:document.location.href//也可以指定专题链接,如:http://jiaju.sina.com.cn/news/zt/zturl.html } ); wb.showmsg(); </script> </body> </html>
测试微博API /* *author:武明礼 *for:test *developed at :2011.8.29 *Copyright 2011. All rights reserved. */ document.write(‘<script type="text/javascript" src="jquery-1.6.1.min.js"><\/scr‘+‘ipt>‘);//引入jQuery document.write(‘<script type="text/javascript" src="http://i.sso.sina.com.cn/js/sinaSSOManager.js"></scr‘+‘ipt>‘);//引入SSO //document.location.host = ‘sina.com.cn‘; function weibo(){}; weibo.prototype = { init:function(action,type,style){ switch(type){ case "text": var zturl = style.zturl; initText(zturl); break; case "img": initImgWeibo(); break; case "trend": var con = style.topic; var ct = style.count; var len = style.length; trend(con,ct,len); break; } }, uinfo:function(){ return sinaSSOManager.getSinaCookie(); /* return data: ag "8" dob "1982-09-01" email "[email protected]" nick "站在岸上的鱼" sex "1" ssl "0" uid "1627910305" user "mingli.cn" */ } } weibo.prototype.showmsg = function(){ alert(this.unifo); } //话题 function trend(content,count,len){ var count = count || 10; var style = ‘<style>#trendlist li {font-size:12px;height:25px; line-height:25px;}<\/style>‘; document.write(style); var html = ‘<ul id="trendlist" style="font-size:12px;">‘; var url = "http://supports.jiaju.sina.com.cn/api/weibo.php?action=trend&trend="+content+"&page=1&count=" +count+ "&callback=?"; $.getJSON(url, function(data) { var dt = data.statuses; for (var i=0; i < dt.length;i++ ) { document.write(‘<li style="height:25px; line-height:25px;font-size:12px;">‘+dt[i].text.substr(0,len)+‘</li>‘); } }); html += "</ul>"; document.write(html); } //初始化纯文本微博 function initText(url){ var html = ‘<div id="textweibo"><textarea name="content" id="content" rows="5" cols="30"></textarea><br /><input type="submit" id="fbbtn" value="发布"><br /><br /></div>‘; document.write(html); $(‘#fbbtn‘).bind("click",function(){ var text = $("#content").val(); send(1,null,encodeURI(text),url); }); } //初始化图片主传类微博 function initImgWeibo(){ var html = ‘<form name="form" method="post" enctype="multipart/form-data" action="http://supports.jiaju.sina.com.cn/api/weibo.php?action=send&file_tag_name=upfile&type=3"><textarea name="content" id="content" rows="5" cols="30"></textarea><br /><input type="file" id="upfile" name="upfile"> <input type="submit" value="提交"></form>‘; document.write(html); } //发布微博 function send(type,pic,content,url){ var link=‘‘; if(type == 1 && pic == null){ link="http://supports.jiaju.sina.com.cn/api/weibo.php?action=send&type="+type+"&content="+content+" "+url+"&callback=?"; } else if(type == 2 && pic!=‘‘){ link="http://supports.jiaju.sina.com.cn/api/weibo.php?action=send&type="+type+"&content="+content+" "+url+"&url="+pic+"&callback=?"; } $.getJSON(link, function(data) { if(data==‘-1‘){ alert(‘未登录,请先登录‘); }else if(data==‘-2‘){ alert(‘您还没有开通微博!‘); }else if(data.error_code==‘20019‘){ alert(‘内容重复,不要太贪心哦~‘); }else if(data.error_code==‘10016‘){ alert(‘内容为空,禁止发布!‘); }else if(data.mid>0){ alert(‘发布成功‘); }else{ alert(‘发布失败:Error info:‘+data.error); } }); } //转发 function transmit(){ var content=$("#content").val(); var url ="http://supports.jiaju.sina.com.cn/api/weibo.php?action=transmit&content="+content+"&wid=3362282635551012&callback=?"; $.getJSON(url, function(data) { alert(data.id); }); } //评论 function comment(){ var content=$("#content").val(); var url ="http://supports.jiaju.sina.com.cn/api/weibo.php?action=comment&content="+content+"&wid=3362282635551012&callback=?"; $.getJSON(url, function(data) { alert(data.id); }); } //关注 function follow(uid){ var url ="http://supports.jiaju.sina.com.cn/api/weibo.php?action=followme&uid="+uid+"&callback=?"; $.getJSON(url, function(data) { if (data.id || data.error_code == 20506) { alert("已关注"); } }); }
原地址:http://mingli-sina-cn.iteye.com/code
时间: 2024-10-27 12:55:26