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

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

问题描述

近日微博更新了它的API v1.1和我的程序停止工作,但不管我有多文档阅读,我似乎无法真正理解什么是需要让我的codeS的工作。

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.

我用来向工作codeS情况如下:

My used-to-work codes are as below :

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/搜索/ tweets.json json.results json.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?

推荐答案

它不工作的原因

在不良思想的奇妙世界,微博是落霞这个答案,因为2013年5月,和需要,以最低的,你要么用自己的小部件之一,鞋拔它,或您设置一个应用程序,并做应用级认证,即使是公共时间轴GET请求。 [ <一个href=\"http://stackoverflow.com/questions/13056432/fetch-public-tweets-via-twitter-api-1-1-via-client-side-$c$c-js\">From这个帖子 ]

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你要么'砍'在一起的东西(的强烈建议不要的,如果他们改变code的一行在他们的小工具,你的code将完全停止工作),或者你做他们建议,并升级到验证请求,使用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.

链接,您必须阅读

所以,你不能只是改变在 / 1 / /1.1 / 的URL,并期望它的工作。

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

<一个href=\"http://stackoverflow.com/questions/17166740/twitter-api-please-migrate-to-api-v1-1/17167138#17167138\">This帖子说明1.0 API是如何去precated,提供的证据来自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.

<一个href=\"http://stackoverflow.com/questions/17166727/how-to-get-twitter-feed-form-twitter-api-1-1/17167256#17167256\">This帖子对1.1 API的一些信息,并将其返回如何JSON格式的数据。

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

<一个href=\"http://stackoverflow.com/questions/17057941/twitter-api-get-user-follower-count-with-1-1/17061274#17061274\">This帖子解释说,如果你尝试,从现在起作出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.

<一个href=\"http://stackoverflow.com/questions/17018748/how-can-i-get-twitter-followers-using-http-request/17019833#17019833\">This帖子解释了什么是错误你得到手段

This post explains what the error you're getting means

...最后,<一href=\"http://stackoverflow.com/questions/12916539/simplest-php-example-retrieving-user-timeline-with-twitter-api-version-1-1/15314662#15314662\">This帖子解释一步一步如何,如果您选择使用的 PHP 作为您的服务器端语言,你让验证请求,并需要一个简单的库(单个文件包括),以得到它的工作。

...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,只要微博使得更新自己的小部件破解的东西,就是这样,你就完蛋了。使用服务器端语言和做正确按他们的文档

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 1.1版 - 的JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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