使用 API 1.1 获取最新推文 [英] Getting latest Tweets with API 1.1
问题描述
我一直使用这个地址来获取我所有的推文:
I've always used this address to get all my tweets:
http://api.twitter.com/1/statuses/user_timeline.json?screen_name=enriquemoreno
但由于 API 1.1 已过时且 API 1 已弃用,我想我会尝试更改.但是新地址不起作用:
but since API 1.1 is out and API 1 is deprecated I thought I would try change. But the new address is not working:
http://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=enriquemoreno
我错过了什么?
推荐答案
某人 用 vanilla javascript 编写了一个(聪明的)片段来获取 twitter 小部件:
Someone wrote a (clever) snippet in vanilla javascript that fetches twitter widgets:
/*********************************************************************
#### Twitter Post Fetcher! ####
Coded by Jason Mayes 2013.
www.jasonmayes.com
Please keep this disclaimer with my code if you use it. Thanks. :-)
Got feedback or questions, ask here: http://goo.gl/JinwJ
*********************************************************************/
var twitterFetcher=function(){var d=null;return{fetch:function(a,b){d=b;var c=document.createElement("script");c.type="text/javascript";c.src="http://cdn.syndication.twimg.com/widgets/timelines/"+a+"?&lang=en&callback=twitterFetcher.callback&suppress_response_codes=true&rnd="+Math.random();document.getElementsByTagName("head")[0].appendChild(c)},callback:function(a){var b=document.createElement("div");b.innerHTML=a.body;a=b.getElementsByClassName("e-entry-title");d(a)}}}();
/*
* ### HOW TO USE: ###
* Create an ID:
* Go to www.twitter.com and sign in as normal, go to your settings page.
* Go to "Widgets" on the left hand side.
* Create a new widget for "user timeline". Feel free to check "exclude replies"
* if you dont want replies in results.
* Now go back to settings page, and then go back to widgets page, you should
* see the widget you just created. Click edit.
* Now look at the URL in your web browser, you will see a long number like this:
* 345735908357048478
* Use this as your ID below instead!
*/
twitterFetcher.fetch('345170787868762112', function(tweets){
// Do what you want with your tweets here! For example:
var x = tweets.length;
var n = 0;
var element = document.getElementById('tweets');
var html = '<ul>';
while(n < x) {
if (tweets[n].innerText) {
html += '<li>' + tweets[n].innerText + '</li>';
} else {
html += '<li>' + tweets[n].textContent + '</li>';
}
n++;
}
html += '</ul>';
element.innerHTML = html;
});
http://jsfiddle.net/jmayes/maT2Z/
这不是最干净的方式,也可能不是面向未来的,但目前唯一的解决方案(我知道)在没有 OAuth 和服务器端支持的情况下访问 Twitter 数据.
Not the cleanest way and maybe not future-proof, but for now the only solution (I know) to access twitter data without OAuth and server-side support.
这篇关于使用 API 1.1 获取最新推文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!