1

When contacting the Embedly API like this:

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

I get the embed data. But when i try doing it with multiple URLs:

$.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"
}));

I get an error response from the API saying the URL was not found:

[
    {
        "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"
    }
]
  • Possible duplicate of http://stackoverflow.com/questions/20148239/use-multiple-urls-with-getjson . You have to make seperate $.getJSON calls. – allu Mar 21 '16 at 10:57
  • Well, since the API responds correctly when only one URL is supplied, making separate calls for each URL would work. But according to the [Embedly docs](http://docs.embed.ly/docs/oembed), multiple URLs in the same API call are supported, and are processed in parallel which is a feature I would like to leverage. – Dejan Draganić Mar 21 '16 at 11:04
  • You are correct, it should work like you described. I didn't manage to find any usage examples. Have you tried the jQuery plugin https://github.com/embedly/embedly-jquery . There I saw a way to use multiple urls. – allu Mar 21 '16 at 11:37

1 Answers1

1

Try:

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)})
screeley
  • 181
  • 3
  • That works! It seems that making the request by simply concatenating the parameters to the URL your way works just fine, but doing it my way (the way shown in the docs) doesn't work. The URL encoding and joining I already did server side. Thanks a lot! – Dejan Draganić Mar 21 '16 at 17:33