使用多个URL时,嵌入式API响应404

时间:2016-03-21 10:23:10

标签: javascript embedly

联系Embedly API时:

$.getJSON('https://api.embedly.com/1/oembed?' + $.param({
    url: 'http://example.com/article-1',
    key: "myapikey"
}));

我得到了嵌入数据。但是,当我尝试使用多个URL时:

$.getJSON('https://api.embedly.com/1/oembed?' + $.param({
    urls: 'http://example.com/article-1,http://example.com/article-2,http://example.com/article-3',
    key: "myapikey"
}));

我从API收到错误响应,说明找不到该网址:

[
    {
        "url": "http://example.com/article-1,http://example.com/article-2,http://example.com/article-3", 
        "error_code": 404, 
        "error_message": "HTTP 404: Not Found", 
        "type": "error", 
        "version": "1.0"
    }
]

1 个答案:

答案 0 :(得分:0)

尝试:

var urls = [
  'http://example.com/article-1',
  'http://example.com/article-2',
  'http://example.com/article-3'
].map(encodeURIComponent).join(',');

$.getJSON('https://api.embedly.com/1/oembed?key=myapikey&urls='+urls)
  .then(function(results){console.log(results)})