Twitter o嵌入跨源请求被阻止
Twitter oEmbed cross-origin request blocked
>我正在尝试使用Twitter oEmbed API来请求嵌入式推文。代码现在非常简单:
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET", "https://api.twitter.com/1/statuses/oembed.json?id=507185938620219395", true);
xmlhttp.send();
我在 Firefox 中收到跨域请求被阻止错误。我做错了什么?
答案是"use jsonp"
$.ajax({
type: "GET",
url: "http://api.twitter.com/1/statuses/oembed.json?id=507185938620219395",
dataType: "jsonp",
success: function(data){
console.log(data);
}
});
https://ctrlq.org/code/19933-embed-tweet-with-javascript
这是修复错误的解决方法
<!--
Written by Amit Agarwal amit@labnol.org
Paste this anywhere between the body tag
-->
<style>
#tweet {
width: 400px !important;
}
#tweet iframe {
border: none !important;
box-shadow: none !important;
}
</style>
<div id="tweet" tweetID="515490786800963584"></div>
<script sync src="https://platform.twitter.com/widgets.js"></script>
<script>
window.onload = (function(){
var tweet = document.getElementById("tweet");
var id = tweet.getAttribute("tweetID");
twttr.widgets.createTweet(
id, tweet,
{
conversation : 'none', // or all
cards : 'hidden', // or visible
linkColor : '#cc0000', // default is blue
theme : 'light' // or dark
})
.then (function (el) {
el.contentDocument.querySelector(".footer").style.display = "none";
});
});
</script>
相关文章:
- ajax请求的顺序总是不同的
- Meteor如何接收HTTP请求
- 有没有一种方法可以防止img get请求使用css或js发生
- 在Twitter上用ie9中的空白src访问iframe的contentWindow
- 从ajax请求中获取javascript对象
- Twitter Bootstrap typeahead:使用“this”获取上下文/调用元素
- JSONP请求返回结果,但也触发error_callback
- 在localhost Dev Box上测试JSONP请求的最佳方式
- Ajax请求文档就绪会导致jquery加载缓慢
- MockJax没有在JavaScript应用程序中发送对我AJAX请求的响应
- 通过javascript/html访问twitter共享iframe
- 正在传递JSONP标头's数据参数到另一个文件中的AJAX请求
- Twitter o嵌入跨源请求被阻止
- 如何在Windows 8 JavaScript(Metro)中将twitter oAuth请求令牌转换为访问令牌
- 关于解除twitter引导警报的Ajax请求
- 如何在rails中通过JS请求显示twitter引导模式
- 无法使用ES6 Fetch从Twitter OAuth API请求令牌
- 如何向twitter API发送POST更新请求
- 我向 Twitter API 提出了请求.我怎样才能从我的PHP脚本到我的JavaScript获取JSON响应
- Facebook和twitter的iframe请求访问集'错误