需要帮助转换为 Twitter API v1.1 - JavaScript [英] Need help converting to Twitter API v1.1 - JavaScript

查看:15
本文介绍了需要帮助转换为 Twitter API v1.1 - JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近 Twitter 将其 API 更新为 v1.1,我的程序停止工作,但无论我阅读了多少文档,我似乎都无法真正理解使我的代码工作需要什么.

Recently Twitter updated its API to v1.1 and my program stops working but no matter how much documentation I read, I can't seem to really understand what is needed to make my codes work.

我常用的代码如下:

function getTweets() {

var url = 'http://search.twitter.com/search.json?q=%23yolo&rpp=10&result_type=recent&callback=?';

    $.getJSON(url, function (json) {

        display = [];
        displayDateTime = [];
        if (json.results.length != null) {
            for (var i = 0; i < json.results.length; i++) {
                var time = new Date(json.results[i].created_at);

                display.push("@" + json.results[i].from_user + ": " + json.results[i].text);
                displayDateTime.push("[" + time.toString().substring(0, 19) + "]");

            } //end of for loop

            display.reverse();
            displayDateTime.reverse();

            loadOtherStuffs();
        } //end of if
        else {
            setTimeout(getTweets, 24000);
        }
    });     //end of getJSON
}//end of getTweets()

我尝试将 url 更改为 https://api.twitter.com/1.1/search/tweets.jsonjson.resultsjson.statuses 但它仍然不起作用.似乎需要 oAuth 使这项工作再次发挥作用,但我不太确定.

I tried changing the url to https://api.twitter.com/1.1/search/tweets.json and json.results to json.statuses but it still won't work. It seems that there's a need for oAuth to make this work again but I'm not too sure.

让这项工作再次发挥作用的具体步骤是什么?

What are exactly the steps to make this work again?

推荐答案

不工作的原因

在糟糕想法的美妙世界中,Twitter 正在淘汰这个答案,截至 2013 年 5 月,并且至少需要您使用他们的一个小部件,并将其硬塞进去,或者您设置启动应用程序并进行应用程序级身份验证,即使对于公共时间线 GET 请求也是如此. [来自这篇文章]

In the wonderful world of bad ideas, Twitter is sunsetting this answer, as of May 2013, and will require, at minimum, that you either use one of their widgets, and shoehorn it in, or that you set up an application and do application-level authentication, even for public-timeline GET requests. [From this post]

这是完全正确的.您要么使用他们的 wigets(非常不鼓励,如果他们更改小部件中的一行代码,您的代码将完全停止工作),或者您按照他们的建议进行操作并升级到经过身份验证的请求使用 OAuth 和 1.1 API.

This is entirely true. You either 'hack' together something using their wigets (highly discouraged, and if they change one line of code in their widget, your code will stop working completely), or you do what they suggest and upgrade to authenticated requests using OAuth and the 1.1 API.

必须阅读的链接

因此,您不能只是将 URL 中的 /1/ 更改为 /1.1/ 并期望它起作用.

So, you can't just change the /1/ to /1.1/ in the URL and expect it to work.

这篇文章解释了1.0 API 已弃用,提供来自 twitter 站点的证据,并说明您需要如何执行经过身份验证的请求.

This post explains how the 1.0 API is deprecated, provides evidence from the twitter site, and explains how you need to perform authenticated requests.

这篇文章 有一些关于 1.1 API 以及它如何返回 JSON 格式数据的信息.

This post has a little information on the 1.1 API and how it returns JSON formatted data.

这篇文章说明从现在开始,如果您尝试向 1.0 API 发出任何请求,您将如何获得 410 GONE 状态,以及这意味着什么.

This post explains how you'll get a 410 GONE status if you try and make any requests to the 1.0 API from now on, and what that means.

这篇文章解释了你得到的错误意味着什么

This post explains what the error you're getting means

...最后,这篇文章 逐步说明了如果您选择使用 作为您的服务器端语言,您发出经过身份验证的请求并需要一个简单的库(单个文件包含)才能使其工作.

...and finally, This post explains step-by-step how, if you choose to use php as your server-side language, you make authenticated requests and requires a simple library (single file include) to get it to work.

结束

不要使用 JavaScript 一起破解某些东西,一旦 Twitter 更新了他们的小部件,就是这样,你就完蛋了.使用服务器端语言并按照他们的文档正确执行.

Don't hack something together using JavaScript, as soon as Twitter makes an update to their widget, that's it, you're screwed. Use a server-side language and do it properly as per their documentation.

这篇关于需要帮助转换为 Twitter API v1.1 - JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆