Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
663 views
in Technique[技术] by (71.8m points)

jquery - Response for JSONp request to youtube oembed call giving "invalid label" error

I am making a JSONp call to youtube using oembed and on response firebug gives "invalid label" error

Here is my code

site = "www.youtube.com";
url = "http://www.youtube.com/watch?v=slORb622ZI8";

$.getJSON("http://"+site+"/oembed?callback=?",{"format":"json","url":url},function(data){
    alert("hello:
"+data);
    alert(data.provider_url);
});

Anyone ran into similar problem with oembed jsonp requests?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Problem

YouTube API doesn't support JSONP - see:

Solution

There is no need for a server-side proxy and no API keys are required.

Instead of:

var url = "http://www.youtube.com/watch?v=slORb622ZI8";

$.getJSON("http://www.youtube.com/oembed?callback=?",
    {"format": "json", "url": url}, function (data) {
    alert("hello:
"+data);
    alert(data.provider_url);
});

Try this, using the Noembed service:

var url = "http://www.youtube.com/watch?v=slORb622ZI8";

$.getJSON("https://noembed.com/embed?callback=?",
    {"format": "json", "url": url}, function (data) {
    alert("hello:
" + data);
    alert(data.provider_url);
});

As a bonus this will also work with Vimeo links when you change url to:

var url = "https://vimeo.com/45196609";

and many other supported sites.

Demo

See DEMO on JS Fiddle.

See also

See also those questions:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...