Reputation: 131
I'm trying to have this in Jquery:
function getfromuser(username) {
var contenitore = [];
var appourl = 'https://api.twitter.com/1/friends/ids.json?cursor=-1&screen_name=' + username;
$.getJSON(appourl, function(data) {
$.each(data, function(i, item) {
if (item.ids !== undefined) {
for (var i=0, elemento; elemento = item.ids[i++];) {
contenitore[i]=item;
};
};
});
});
getid(contenitore);
};
I need only to store the IDS in an array. But calling: https://api.twitter.com/1/friends/ids.json?cursor=-1&screen_name=xxxxxx I got the error:
XMLHttpRequest cannot load https://api.twitter.com/1/friends/ids.json?cursor=-1&screen_name=xxxxxx. Origin null is not allowed by Access-Control-Allow-Origin
Any help?
Upvotes: 1
Views: 1172
Reputation: 18979
You need to request JSONP, otherwise this is XSS. You can do this by simply providing the callback param in the URL:
var appourl = 'https://api.twitter.com/1/friends/ids.json?cursor=-1&callback=?&screen_name=' + username;
Here a working jsFiddle
function getfromuser(username) {
var contenitore = [];
var appourl = 'https://api.twitter.com/1/friends/ids.json?cursor=-1&callback=?&screen_name=' + username;
$.getJSON(appourl, function(data) {
console.log(data);
});
};
getfromuser('unclebobmartin');
Upvotes: 2