如何获取用户的Twitter图片?

时间:2011-02-28 22:07:46

标签: twitter

我正在制作一个人们输入推特用户名的网站。现在我想加载放入的名称的twitterimage。我已经在互联网上搜索了但是找不到一个很好的简单方法来实现它。我是否需要使用一些花哨的twitter api或其他东西?任何简单的API? (它只适用于一个简单的网站)或名称为变量的URL吗?

2 个答案:

答案 0 :(得分:5)

这有效:

<!DOCTYPE html>
    <html>
    <head>
    <script type="text/javascript">

    function GetImage(){

        var txtBox = document.getElementById("twit");
        var imgTwitter = document.getElementById("imgTwitter");
        imgTwitter.src = "http://api.twitter.com/1/users/profile_image/" + txtBox.value;

    }


    </script>
    </head>
    <body>

    <input name="twit" id="twit" type="text"><a href="#" onclick="javascript:GetImage();">Get Image</a>


    <img id="imgTwitter"  >

    </body>
    </html>

答案 1 :(得分:-1)

从这个问题: https://stackoverflow.com/a/30322178/6539400

https://twitter.com/[screen_name]/profile_image?size=mini
https://twitter.com/[screen_name]/profile_image?size=normal
https://twitter.com/[screen_name]/profile_image?size=bigger
https://twitter.com/[screen_name]/profile_image?size=original

&#13;
&#13;
function ClickFunction() {
	document.getElementById("content").innerHTML = "";

	var frag = document.createDocumentFragment();
	var uname = document.getElementById("name").value;

	var SRCmini = "https://twitter.com/" + uname + "/profile_image?size=mini";
	var SRCnormal = "https://twitter.com/" + uname + "/profile_image?size=normal";
	var SRCbigger = "https://twitter.com/" + uname + "/profile_image?size=bigger";
	var SRCoriginal = "https://twitter.com/" + uname + "/profile_image?size=original";

	frag.appendChild(document.createTextNode(SRCmini));
	frag.appendChild(document.createElement("br"));
	var IMGmini = frag.appendChild(document.createElement("img"));
		IMGmini.src = SRCmini;
	frag.appendChild(document.createElement("br"));

	frag.appendChild(document.createTextNode(SRCnormal));
	frag.appendChild(document.createElement("br"));
	var IMGnormal = frag.appendChild(document.createElement("img"));
		IMGnormal.src = SRCnormal;
	frag.appendChild(document.createElement("br"));

	frag.appendChild(document.createTextNode(SRCbigger));
	frag.appendChild(document.createElement("br"));
	var IMGbigger = frag.appendChild(document.createElement("img"));
		IMGbigger.src = SRCbigger;
	frag.appendChild(document.createElement("br"));

	frag.appendChild(document.createTextNode(SRCoriginal));
	frag.appendChild(document.createElement("br"));
	var IMGoriginal = frag.appendChild(document.createElement("img"));
		IMGoriginal.src = SRCoriginal;
	frag.appendChild(document.createElement("br"));

	document.getElementById("content").appendChild(frag);
}
&#13;
<input id="name" value="wikipedia" /><br />
<button onclick="ClickFunction()">Click here!</button><br /><br />


<div id="content"></div>
&#13;
&#13;
&#13;