When trying to perform an API call to Twitter, I noticed I must use “jsonp” to bypass the cross-domain problem. Using “json” dataType will throw a 400 “Control-Allow-Origin” error.
On the other hand, when I’m switching to jsonp I’m always receiving a 400 error with the following message:
jquery.min.js:4 GET https://api.twitter.com/1.1/search/tweets.json?callback=aloha&q=dog
Any ideas on what I’m doing wrong here and how to get it fixed?
function aloha(result) {
debugger;
};
var twitter_call = $.getJSON({
type: 'GET',
contentType: 'application/javascript',
dataType: 'jsonp',
cache: true,
jsonpCallback: 'aloha',
url: 'https://api.twitter.com/1.1/search/tweets.json',
crossDomain: true,
headers: {
"Authorization": "Bearer MY_BEARER_TOKEN"
},
data: {
"q":"dog"
}
});