javascript 显示 Twitter 提要停止工作

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12845545/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 17:14:48  来源:igfitidea点击:

Displaying Twitter feed stopped working

javascripthtmltwitterfeed

提问by Henrik Petterson

The default way to display a twitter feed has stopped working. Here is an example code:

显示 Twitter 提要的默认方式已停止工作。这是一个示例代码:

<html>
    <head>
        <script type="text/javascript" src="http://twitter.com/javascripts/blogger.js"></script>
    </head>
    <body>
        The feed should display below:
        <div id="twitter_update_list"> </div>
        <script type="text/javascript" src="http://twitter.com/statuses/user_timeline/stackoverflow.json?callback=twitterCallback2&amp;count=4">
    </body>
</html>

Why is this not working?I suspected that the issue was on Twitter's end but this has not functioned for a while now. I created a fiddle in case you want to play: http://jsfiddle.net/9EvXn/

为什么这不起作用?我怀疑问题出在 Twitter 的末尾,但现在已经有一段时间没有运行了。我创建了一个小提琴以防你想玩:http: //jsfiddle.net/9EvXn/

回答by Gary Woods

You need to update your code to Twitter's new API. This code will work:

您需要将代码更新为 Twitter 的新 API。此代码将起作用:

<html>
    <head>
        <script type="text/javascript" src="http://twitter.com/javascripts/blogger.js"></script>
    </head>
    <body>
 <div id="twitter_update_list"></div>
            <script type="text/javascript" src="http://api.twitter.com/1/statuses/user_timeline.json?screen_name=stackoverflow&include_rts=true&count=4&callback=twitterCallback2"></script>
</div>
    </body>
</html>

Pay attention to this line of code that is updated:

注意更新的这行代码:

http://api.twitter.com/1/statuses/user_timeline.json?screen_name=stackoverflow&include_rts=true&count=4&callback=twitterCallback2

回答by powerbuoy

Someone recently wrote this on my blog (as a comment to an article on displaying Twitter feeds):

最近有人在我的博客上写了这个(作为对关于显示 Twitter 提要的文章的评论):

Just a heads up, if you are using this code I've noticed that it stopped working recently. I believe it is due to Twitter's new API. The culprit is the url that fetches the tweets. here is an updated url that seems to fix the issue: var url = 'http://api.twitter.com/1/statuses/user_timeline.json?screen_name=' + username + '&count=' + limit + '&callback=?';

请注意,如果您正在使用此代码,我注意到它最近停止工作。我相信这是由于 Twitter 的新 API。罪魁祸首是获取推文的网址。这是一个更新的网址,似乎可以解决这个问题: var url = 'http://api.twitter.com/1/statuses/user_timeline.json?screen_name=' + username + '&count=' + limit + '&callback=?';

So perhaps just slap "api" in front of "twitter.com". And the /1/ I assume is a version number.

所以也许只是在“twitter.com”前面打“api”。而 /1/ 我假设是一个版本号。

Edit: Apparently this was correct :P

编辑:显然这是正确的:P

<script type="text/javascript" src="http://twitter.com/javascripts/blogger.js"></script>
<div id="twitter_update_list"></div>
<script type="text/javascript" src="http://api.twitter.com/1/statuses/user_timeline.json?screen_name=stackoverflow&include_rts=true&count=4&callback=twitterCallback2"></script>

回答by RASG

looks ok to me.

我觉得没问题。

here, i created a jsfiddle to test: http://jsfiddle.net/RASG/ULZBB/

在这里,我创建了一个 jsfiddle 来测试:http: //jsfiddle.net/RASG/ULZBB/

try editing my jsfiddle, and see if it can help you.

尝试编辑我的 jsfiddle,看看它是否可以帮助你。

回答by afroginthevalley

This is part of Twitter's latest API updates, announced previously (see https://dev.twitter.com/blog/api-housekeepingand https://dev.twitter.com/docs/deprecations/spring-2012).

这是 Twitter 之前宣布的最新 API 更新的一部分(参见https://dev.twitter.com/blog/api-housekeepinghttps://dev.twitter.com/docs/deprecations/spring-2012)。

All calls must now be made the API.twitter.com and using the versionned endpoint (/1.1 ideally, or /1 until March 2012).

现在所有调用都必须通过 API.twitter.com 并使用版本化端点(理想情况下为 /1.1,或 2012 年 3 月之前为 /1)。