使用jsonp dataType调用Twitter的API将引发400错误 [英] Calling Twitter's API with jsonp dataType will throw a 400 error
问题描述
当尝试执行对Twitter的API调用时,我注意到我必须使用"jsonp"来绕过跨域问题.使用"json"数据类型将引发400"Control-Allow-Origin"错误.
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.
另一方面,当我切换到jsonp时,总是收到400错误,并显示以下消息:
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
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?
<script type="text/javascript">
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"
}
});
</script>
推荐答案
Twitter官方不支持此功能,正如其团队在我在其开发论坛上提出的有关该主题的内容所提及的那样:
This is officially unsupported by Twitter as mentioned by their team on this topic I raised on their development forum:
https: //twittercommunity.com/t/error-401-problems-with-jsonp-token-with-twitter-rest-api-ajax/73618
针对该主题找到的任何解决方法都将直接发布在该链接中.
Any workarounds found for this topic will be posted directly in that link.
这篇关于使用jsonp dataType调用Twitter的API将引发400错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!