2010-10-10 97 views
6

有誰知道如何檢查Youtube視頻是否可以使用Youtube API嵌入?我試過使用這個網址:如何使用Youtube API檢查視頻是否可嵌入?

http://gdata.youtube.com/feeds/api/videos/47z7i79NuK8 

但我得到的響應,粘貼在下面,似乎沒有可嵌入的字段?

entry: 
    rating: 
    rel: http://schemas.google.com/g/2005#overall 
    max: "5" 
    min: "1" 
    average: "4.744681" 
    numRaters: "94" 
    group: 
    duration: 
     seconds: "47" 
    player: 
     url: http://www.youtube.com/watch?v=47z7i79NuK8&feature=youtube_gdata_player 
    category: Entertainment 
    title: "Sesame Street: P is For Princess available everywhere on DVD!" 
    thumbnail: 
    - time: "00:00:23.500" 
     url: http://i.ytimg.com/vi/47z7i79NuK8/2.jpg 
     height: "90" 
     width: "120" 
    - time: "00:00:11.750" 
     url: http://i.ytimg.com/vi/47z7i79NuK8/1.jpg 
     height: "90" 
     width: "120" 
    - time: "00:00:35.250" 
     url: http://i.ytimg.com/vi/47z7i79NuK8/3.jpg 
     height: "90" 
     width: "120" 
    - time: "00:00:23.500" 
     url: http://i.ytimg.com/vi/47z7i79NuK8/0.jpg 
     height: "240" 
     width: "320" 
    content: 
     duration: "47" 
     medium: video 
     yt:format: "5" 
     isDefault: "true" 
     url: http://www.youtube.com/v/47z7i79NuK8?f=videos&app=youtube_gdata 
     expression: full 
     type: application/x-shockwave-flash 
    description: |- 
     "Once upon a time on Sesame Street, there lived a fairy-in-training named Abby Cadabby, and she loved playing princess with friends like Rosita. But what happens when a misguided Prince (actor Paul Rudd) tries to rescue them? Pretending and the Letter P are the focus of this enchanting title, which also features fun with Natalie Portman and Elmo in "The Princess and The Elephant." This DVD also includes two bonus episodes of Sesame Street's new animated show, Abby's Flying Fairy School." 

     www.sesamestreet.org/princess 
    keywords: sesame street, muppets, princess, dvd, abby, abby's flying fairy school 
    control: 
    state: Syndication of this video was restricted by its owner. 
    category: 
    - term: http://gdata.youtube.com/schemas/2007#video 
    scheme: http://schemas.google.com/g/2005#kind 
    - label: Entertainment 
    term: Entertainment 
    scheme: http://gdata.youtube.com/schemas/2007/categories.cat 
    - term: sesame street 
    scheme: http://gdata.youtube.com/schemas/2007/keywords.cat 
    - term: muppets 
    scheme: http://gdata.youtube.com/schemas/2007/keywords.cat 
    - term: princess 
    scheme: http://gdata.youtube.com/schemas/2007/keywords.cat 
    - term: dvd 
    scheme: http://gdata.youtube.com/schemas/2007/keywords.cat 
    - term: abby 
    scheme: http://gdata.youtube.com/schemas/2007/keywords.cat 
    - term: abby's flying fairy school 
    scheme: http://gdata.youtube.com/schemas/2007/keywords.cat 
    comments: 
    feedLink: 
     href: http://gdata.youtube.com/feeds/api/videos/47z7i79NuK8/comments 
     countHint: "80" 
    author: 
    name: SesameStreet 
    uri: http://gdata.youtube.com/feeds/api/users/sesamestreet 
    title: "Sesame Street: P is For Princess available everywhere on DVD!" 
    statistics: 
    favoriteCount: "43" 
    viewCount: "6003" 
    published: "2010-10-08T19:18:09.000Z" 
    xmlns:yt: http://gdata.youtube.com/schemas/2007 
    id: http://gdata.youtube.com/feeds/api/videos/47z7i79NuK8 
    xmlns:gd: http://schemas.google.com/g/2005 
    content: |- 
    "Once upon a time on Sesame Street, there lived a fairy-in-training named Abby Cadabby, and she loved playing princess with friends like Rosita. But what happens when a misguided Prince (actor Paul Rudd) tries to rescue them? Pretending and the Letter P are the focus of this enchanting title, which also features fun with Natalie Portman and Elmo in "The Princess and The Elephant." This DVD also includes two bonus episodes of Sesame Street's new animated show, Abby's Flying Fairy School." 

    www.sesamestreet.org/princess 
    link: 
    - href: http://www.youtube.com/watch?v=47z7i79NuK8&feature=youtube_gdata 
    rel: alternate 
    type: text/html 
    - href: http://gdata.youtube.com/feeds/api/videos/47z7i79NuK8/related 
    rel: http://gdata.youtube.com/schemas/2007#video.related 
    type: application/atom+xml 
    - href: http://gdata.youtube.com/feeds/api/videos/47z7i79NuK8 
    rel: self 
    type: application/atom+xml 
    xmlns:media: http://search.yahoo.com/mrss/ 
    updated: "2010-10-10T06:36:39.000Z" 
    xmlns:app: http://purl.org/atom/app# 
    xmlns: http://www.w3.org/2005/Atom 

回答

8

望着YouTube API reference,看來你有一對夫婦選擇:

爲剪輯搜索時指定「格式」參數:

格式參數指定的影片必須在提供特定的視頻格式。您的請求可以指定以下任何格式:

- 此視頻的嵌入式播放器(SWF)的HTTP網址。此格式不適用於不可嵌入的視頻。開發人員通常會將& format = 5添加到其查詢中,以將結果限制爲可嵌入其網站的視頻。

或參考的YT:AccessControl的元素:

<yt:accessControl>標記表示是否允許用戶對視頻評分,添加關於視頻,速度評論有關視頻,添加視頻響應視頻,或將視頻嵌入第三方網站。另一個設置指示YouTube是否可以在YouTube.com網站以外的YouTube媒體資源上展示該視頻。

語法看起來像<yt:accessControl action='embed' permission='allowed'/>

所以,在你的榜樣,它看起來像行yt:format: "5"告訴你的夾子可以嵌入。

1

如果視頻不可嵌入,則XML應包含<yt:noembed/>Example

+0

這似乎並不總是如此。例如,http://gdata.youtube.com/feeds/api/videos/-KYUPJIzCyM沒有此標籤,但是在無鑲邊播放器中,我無法將其嵌入。但也許這只是我? – 2012-03-25 02:09:12

2

如果您可以使用新的無對象的方式顯示視頻,那麼您會發現幾乎所有無法用對象標記查看的視頻都是完美無缺的。

語法是:

< IFRAME類= 「YouTube的玩家」 寬度= 「340」 高度= 「220」 SRC = 「http://www.youtube.com/embed/YER_VIDEO_ID_HERE」 frameborder =「0」> </iframe >

您目前無法信任yt:accessControl。

+0

嗨,我使用相同的方式獲取YouTube視頻 我打的API是: http://gdata.youtube.com/feeds/api/charts/movies/trending?v=2&paid-content=false&hl=en&alt = json&format = 5 你可以請建議一些方法,以便我可以發送一些參數在這個API可以過濾結果的基礎上的YT:accsessControl嵌入和辛迪加領域...所以如何嵌入這個領域的API來過濾結果 – Bhupendra 2012-10-07 17:21:59

6

從YouTube V3 API開始,在狀態部分有一個embeddable字段。

E.g.https://www.googleapis.com/youtube/v3/videos?id=6CQEZ_kas0I&key=[yourkey]&part=snippet,contentDetails,status

"status": { 
    "uploadStatus": "processed", 
    "privacyStatus": "public", 
    "license": "youtube", 
    "embeddable": true, 
    "publicStatsViewable": true 
} 
+0

謝謝,這正是我一直在尋找的!令人遺憾的是,API並沒有立即告訴我們這樣的東西,從來沒有想過它會處於狀態。 – 2015-12-18 13:30:04

4

在YouTube的V3 API,只返回是嵌入視頻,添加 videoEmbeddable=true參數。您也必須使用type=video才能正常工作。