2015-05-13 33 views
0

編輯 我似乎能夠從用戶名獲得視頻,如果用戶名是唯一的話。但不是來自帶有雙字用戶名的頻道(例如,名稱之間有空格)。從2部分的用戶名獲取YouTube視頻API的視頻

我試圖通過youtube的v3 api獲取視頻。我以前做過,但是這次我無法讓它工作。

 $.get(
      "https://www.googleapis.com/youtube/v3/channels", { 
       part: 'contentDetails', 
       forUsername: 'Gunnar+Base', 
       id: 'UCI8vMgRRdio_jtoNbZ6dIlw', 
       key: 'xxx', 
      }, 
      function (data) { 
       $.each(data.items, function (i, item) { 
        pid = item.contentDetails.relatedPlaylists.uploads; 
        console.log(pid); 

        //DO another call for the videos and loop them out. 
       }); 
      } 
     ); 

此代碼適用於另一個項目。我已經啓用了API並獲得了一個關鍵。唯一的問題是YouTube無法找到與該帳戶相關的任何渠道。該帳戶雖然有幾個上傳的視頻。我正在通過API瀏覽器測試調用,但它似乎無法找到用戶。儘管如此,我可以找到其他渠道。唯一不同的是我有2個單詞作爲頻道名稱。 https://developers.google.com/youtube/v3/docs/channels/list

回答

0

這可能是有史以來最愚蠢的事情。如果你有一個雙字的用戶名,你必須找到你的channelid,並使用它來代替fromUsername。

"https://www.googleapis.com/youtube/v3/channels", { 
       part: 'contentDetails', 
       id: 'Channelid', 
       key: 'xx', 
      }, 

,而不是

"https://www.googleapis.com/youtube/v3/channels", { 
        part: 'contentDetails', 
        fromUsername: 'Username Secondword', 
        key: 'xx', 
       },