Can / statuses / user_timeline still read through JavaScript?

I previously used some jQuery to read twitter tweets:

$.ajax('https://api.twitter.com/1/statuses/user_timeline.json', { crossDomain: true, data: { screen_name: 'twitterapi', count: 5 }, dataType: 'jsonp' }).done(function (tweets) { console.log(tweets); }); 

Since twitter rejects their API 1.0 and requires OAuth for the 1.1 API, I tried to find out if everything is possible to get the tweet data in the same way.

Just change the url to:

 https://api.twitter.com/1.1/statuses/user_timeline.json 

Results in 400 Bad Request response without message.

I know there is a twitter tool to create an OAuth signature for a request, but I'm not sure how to use it with a JSONP request, or even if it can be used with a JSONP request.

Is it still possible to read the user’s timeline in the Twitter 1.1 API?

+6
source share
4 answers

If you look at Twitter Error Codes and Answers , a status code of 400 means:

The request is invalid. The accompanying error message will explain why. This status code will be returned during version 1.0 speed limit. In API v1.1, a request without authentication is considered invalid and you will receive this response.

Thus, although the code 400 means that you have exceeded the speed limit, now it also returns when the request is not authenticated.

To authenticate the request, you need to add the Oauth Authorization header. There are several libraries that can help with this, but the problem is that in order to generate an Oauth signature, you will have to hard-code your application keys (including the secret key) into your client-side code that will open it to end users (not a good idea )

It is best to set up a proxy server on your server - make a GET server with the Oauth header and use ajax to receive tweets from your server.

+5
source

redhotvengeance is correct, the server side is your only safe option since March 2013 , except that my recommended solution would be to install cronjob and cache the results somewhere. Using a proxy is a great way to quickly click Speed ​​Limits !

For example, if you plan to use the user_timeline part of the API, you are limited to 15 requests in 15 minutes, so if you get more than 60 views per page per hour, you will exchange these 400 errors for 429 errors !

+4
source

As stated here regarding a way to get a custom timeline with pure client JS:

If we want, we can still parse their pages and redefine at least some of the lost functions with pure client JS.

We need: a CORS proxy server that can work with HTTPS pages (the only thing I know is the YQL API) and knowledge of how information is deleted on its public pages. With this in mind, we can get, for example, the last 20 tweets from the user, as it was in the demo: http://jsbin.com/agejol/1 (click "Change in JSBin" to view the code)

PS I know that this may violate their policies, but I take care of it just as they cared for us when they dropped all of their client APIs.

0
source

Source: https://habr.com/ru/post/925682/


All Articles