Change server-side to client-side with Ajax and Twitter API 1.1?


#1

Hello, sorry for advance my English is not very good.

It’s possible to get real time tweets with some filters (with the words “foo” and/or “bar” for example) with Ajax request?
Today, I calling the API on server-side (with TwitterOAuth) but i’m stuck with the rate limit of 180 per 15 minutes window because of that (and I just have one ip).

If i call the API on the client-side, the rate limit is for the end-user IP. Right?
My website is under development but the amount of visitors will exceed the 180 connections.

Thank you for your help.
Regards


#2

IP addresses have no role in rate limiting API v1.1. An application has an application-based pool and user-application-based pools, one for each access token.

Often client-side non-user-based API calls aren’t practical with API v1.1.

To scale your use of the API directly with your end-user usage, you need to require users to authorize your app to make requests on their behalf.

Otherwise, I would do the work server-side and decouple your use of the API from direct user action, instead collecting the tweets you need in the background and displaying to users results based on what your back end has collected.


#3

Thank you for your reply.

The most of my visitors are not authentificated as Twitter user. There is a way for these to get live streaming of tweets without affect the rate limit of my application? I just tested the “application-only” authentification and my rate limit has increased to 450. But i’m still stuck with the “global” influence limiting of my application.

In fact, if user A call the API in AJAX, the rate limit of my application down. If user B call the API in the same way, in another computer, the rate limit of my application still down.

I’m sorry if this is not clear. Thank you.


#4

@docteurSAS why not use the streaming API (cf. https://dev.twitter.com/docs/streaming-apis/streams/public). This is still server side, but should let you stream the tweets without having to suffer the REST API limits…

Hope this helps,

Mehdi.


#5

Hi there!
Yes, I use the streaming API with PHP CURL and AJAX now :slight_smile:


#6

Hi ,
I am trying to access specific tag or user public feed cilent side using Jquery , Ajax and JS. but i am getting error.
see my code below.
$.ajax({
url: “https://api.twitter.com/1.1/search/tweets.json”,
type: “POST”,
data: {q:‘twitter’ },
cache: false,
dataType: ‘jsonp’,
beforeSend: setHeader,
success: function(data) { alert(‘hello!’); console.log(data);},
error: function(html) { alert(html); },
});
function setHeader(xhr) {
if(xhr && xhr.overrideMimeType) {
xhr.overrideMimeType(“application/j-son;charset=UTF-8”);
}
xhr.setRequestHeader(‘Authorization: OAuth oauth_consumer_key=“7a3ansbRTfOBdX4hn2sQJp72a”, oauth_nonce=“f07786e34733202848a46124dd73afcf”, oauth_signature=“TonfG1pbS%2BseiXOlyYl44oZAwPw%3D”, oauth_signature_method=“HMAC-SHA1”, oauth_timestamp=“1435660267”, oauth_token=“468141855-Id6phQoOE66n9CBzAdwEUAuQI2TBmxGyUHL9xarx”, oauth_version=“1.0”’);
}

}

but it getting 401 and 400 error.