Twitter user_timeline JSONP. No response

2019-08-07 15:24发布

Solved

The problem is that Twitter now (stupidly) requires OAuth even for public data. An easy enough workaround is to have a local php script which OAuths and gets the data and access that with Ajax as opposed to Ajaxing twitter directly.


I'm currently trying to pull user timelines from twitter using the Reqwest JavaScript library. However when I do so the request is considered successful but no data is retrieved and the console displays a GET error. The code im trying is as follows:

$.domReady(function () {

    $.ajax({
        url: 'http://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=twitter',
        type: 'jsonp',
        success: function (response) {
            console.log(response);
        },
        error: function (err) {
            console.log(err);
        }
    });

})

3条回答
对你真心纯属浪费
2楼-- · 2019-08-07 15:36

If we want to, we can still parse their pages and reimplement at least a bit of lost functionality with pure client-side JS.

What we need is: a CORS proxy that can deal with HTTPS pages (the only I know is YQL APIs) and the knowledge of how the information is retreived on their public pages. Keeping this in mind, we can fetch, for example, recent 20 tweets from a user, as I did in the demo: http://jsbin.com/agejol/1 (click "Edit in JSBin" to view the code)

P.S. I know this may violate their policy but I care about it just as much as they cared about us when they dropped all their client-side APIs.

查看更多
疯言疯语
3楼-- · 2019-08-07 15:40

I just updated a plugin of mine to work with the Twitter 1.1 API. Unfortunately, per Twitter's urging, you will have to perform the actual request from server-side code. However, you can pass the response to the plugin and it will take care of the rest. I don't know what framework you are running, but I have already added sample code for making the request in C#, and will be adding sample code for PHP, shortly.

查看更多
淡お忘
4楼-- · 2019-08-07 15:56

Try to pass parameter jsoncallback. http://jsfiddle.net/CCTKa/

I just got Bad Authentication data error.

查看更多
登录 后发表回答