0
使用python -m SimpleHTTPServer 8080
測試JS,我已經建立了一個D3即但是遇到問題用下面的代碼訪問instagram's api using oembed:使用instagram的dembed與d3?
d3.json("http://api.instagram.com/oembed?url=https://instagram.com/p/rigacvhhTe/", function(error, json) {
if (error) return console.warn(error);
console.log(json);
});
錯誤:
XMLHttpRequest cannot load http://api.instagram.com/oembed?url=https://instagram.com/p/rigacvhhTe/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.
成功的響應應該返回這個以.json :
{
provider_url: "http://instagram.com/",
media_id: "784331840172725470_179100388",
author_name: "simplyclimb",
height: null,
thumbnail_url: "http://photos-d.ak.instagram.com/hphotos-ak-xpa1/t51.2885-15/10523538_897068253642371_552234973_n.jpg",
thumbnail_width: 640,
thumbnail_height: 640,
provider_name: "Instagram",
title: "Big day.",
html: "<blockquote class="instagram-media" data-instgrm-captioned data-instgrm-version="4" style=" background:#FFF; border:0; border-radius:3px; box-shadow:0 0 1px 0 rgba(0,0,0,0.5),0 1px 10px 0 rgba(0,0,0,0.15); margin: 1px; max-width:658px; padding:0; width:99.375%; width:-webkit-calc(100% - 2px); width:calc(100% - 2px);"><div style="padding:8px;"> <div style=" background:#F8F8F8; line-height:0; margin-top:40px; padding:50% 0; text-align:center; width:100%;"> <div style=" background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACwAAAAsCAMAAAApWqozAAAAGFBMVEUiIiI9PT0eHh4gIB4hIBkcHBwcHBwcHBydr+JQAAAACHRSTlMABA4YHyQsM5jtaMwAAADfSURBVDjL7ZVBEgMhCAQBAf//42xcNbpAqakcM0ftUmFAAIBE81IqBJdS3lS6zs3bIpB9WED3YYXFPmHRfT8sgyrCP1x8uEUxLMzNWElFOYCV6mHWWwMzdPEKHlhLw7NWJqkHc4uIZphavDzA2JPzUDsBZziNae2S6owH8xPmX8G7zzgKEOPUoYHvGz1TBCxMkd3kwNVbU0gKHkx+iZILf77IofhrY1nYFnB/lQPb79drWOyJVa/DAvg9B/rLB4cC+Nqgdz/TvBbBnr6GBReqn/nRmDgaQEej7WhonozjF+Y2I/fZou/qAAAAAElFTkSuQmCC); display:block; height:44px; margin:0 auto -44px; position:relative; top:-22px; width:44px;"></div></div> <p style=" margin:8px 0 0 0; padding:0 4px;"> <a href="https://instagram.com/p/rigacvhhTe/" style=" color:#000; font-family:Arial,sans-serif; font-size:14px; font-style:normal; font-weight:normal; line-height:17px; text-decoration:none; word-wrap:break-word;" target="_top">Big day.</a></p> <p style=" color:#c9c8cd; font-family:Arial,sans-serif; font-size:14px; line-height:17px; margin-bottom:0; margin-top:8px; overflow:hidden; padding:8px 0 7px; text-align:center; text-overflow:ellipsis; white-space:nowrap;">A photo posted by @simplyclimb on <time style=" font-family:Arial,sans-serif; font-size:14px; line-height:17px;" datetime="2014-08-11T01:14:23+00:00">Aug 10, 2014 at 6:14pm PDT</time></p></div></blockquote> <script async defer src="//platform.instagram.com/en_US/embeds.js"></script>",
width: 658,
version: "1.0",
author_url: "http://instagram.com/simplyclimb",
author_id: 179100388,
type: "rich"
}
對於我在做什麼有什麼建議嗎?
該API似乎不支持CORS,因此無法從客戶端腳本訪問它 – adeneo 2015-03-18 21:32:59
然而,Instagram API確實支持JSONP,但它似乎並不像D3支持JSONP。 – adeneo 2015-03-18 21:36:10
@adeneo使用d3的JSONP? http://bl.ocks.org/tmcw/4494715 – blehman 2015-03-18 21:40:01