Authorizing in jquery?


#1

Hello there, well I encounter a problem when trying to create a social counter to my blog
I have this code

var t_page = 'ItzLamboTutos';
$.getJSON('http://cdn.api.twitter.com/1/users/show.json?screen_name='+t_page+'&callback=?', function(data) {
tshare__count = data['followers_count'];
$('.tshare__count').html(tshare__count);
}); 

Try updating the API thus

$.getJSON('https://api.twitter.com/1.1/users/show.json?screen_name='+t_page+'&callback=?', function(data) {
tshare__count = data['followers_count'];
$('.tshare__count').html(tshare__count);
});

But it gives me an error of OAuth, I wonder how could authenticate within the javascript code


#2

Since version 1.1 all Twitter API endpoints require oAuth authentication. Due to the way OAuth works it is no easily possible to do this in Javascript client side, as you would need to give away secret tokens to the user.
A better way is to used a server side script that proxies the response of the request to the API endpoint (and probably cache it for a while to not hit rate limits), which handles the authentication. There are quite a few OAuth libraries out there, maybe you want to have a look for example at TwitterOAuth.


#3

Well, I have achieved I login to the proxy, but now I need to get the information (“followers_count”) that sends me the .php. Any suggestions with jquery?