2016-03-21 33 views
0

当联系时的Embedly API这样与404响应:Embedly API使用多个URL

$.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" 
    } 
] 
+0

的可能的复制http://stackoverflow.com/questions/20148239/use-multiple-urls-with-getjson。您必须进行单独的$ .getJSON调用。 – allu

+0

那么,因为只有一个URL被提供时,API响应正确,因此对每个URL分别调用都是可行的。但根据[Embedly文档](http://docs.embed.ly/docs/oembed),支持同一API调用中的多个URL,并且是并行处理,这是我想要利用的功能。 –

+0

你是对的,它应该像你描述的那样工作。我没有设法找到任何使用示例。你有没有尝试过jQuery插件https://github.com/embedly/embedly-jquery。在那里我看到了使用多个网址的方法。 – allu

回答

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)}) 
+0

工作! 看来,通过简单地将参数连接到URL的方式进行请求的方式工作得很好,但按照我的方式(文档中显示的方式)不起作用。 URL编码和加入我已经做了服务器端。 非常感谢! –