2015-10-20 63 views
1

這是我的代碼。如何過濾YouTube數據API v3中受版權保護的視頻

$videosResponse = $youtube->videos->listVideos('status, fileDetails, snippet, recordingDetails, topicDetails', array(
          'id' => $id, 
          'maxResults' => 1, 
          'part' => 'status,snippet', 
         )); 

下面是響應

object(Google_Service_YouTube_VideoListResponse)#73 (16) { 
      ["collection_key":protected]=> 
      string(5) "items" 
      ["internal_gapi_mappings":protected]=> 
      array(0) { 
      } 
      ["etag"]=> 
      string(57) ""fpJ9onbY0Rl_LqYLG6rOCJ9h9N8/lnLk97dQDMUpWh4EJfvVHiKXvG8"" 
      ["eventId"]=> 
      NULL 
      ["itemsType":protected]=> 
      string(28) "Google_Service_YouTube_Video" 
      ["itemsDataType":protected]=> 
      string(5) "array" 
      ["kind"]=> 
      string(25) "youtube#videoListResponse" 
      ["nextPageToken"]=> 
      NULL 
      ["pageInfoType":protected]=> 
      string(31) "Google_Service_YouTube_PageInfo" 
      ["pageInfoDataType":protected]=> 
      string(0) "" 
      ["prevPageToken"]=> 
      NULL 
      ["tokenPaginationType":protected]=> 
      string(38) "Google_Service_YouTube_TokenPagination" 
      ["tokenPaginationDataType":protected]=> 
      string(0) "" 
      ["visitorId"]=> 
      NULL 
      ["modelData":protected]=> 
      array(2) { 
      ["pageInfo"]=> 
      array(2) { 
       ["totalResults"]=> 
       int(1) 
       ["resultsPerPage"]=> 
       int(1) 
      } 
      ["items"]=> 
      array(1) { 
       [0]=> 
       array(5) { 
       ["kind"]=> 
       string(13) "youtube#video" 
       ["etag"]=> 
       string(57) ""fpJ9onbY0Rl_LqYLG6rOCJ9h9N8/NCacXkm79gLd-LDp1PS5m7Z_FFc"" 
       ["id"]=> 
       string(11) "bdzxVW3zlZ0" 
       ["snippet"]=> 
       array(10) { 
        ["publishedAt"]=> 
        string(24) "2011-11-10T07:13:44.000Z" 
        ["channelId"]=> 
        string(24) "UColEueTkpUJjnDlaO-P14DQ" 
        ["title"]=> 
        string(32) "Leap of Faith Movie_Steve Martin" 
        ["description"]=> 
        string(82) "I created this video with the YouTube Video Editor (http://www.youtube.com/editor)" 
        ["thumbnails"]=> 
        array(4) { 
        ["default"]=> 
        array(3) { 
         ["url"]=> 
         string(46) "https://i.ytimg.com/vi/bdzxVW3zlZ0/default.jpg" 
         ["width"]=> 
         int(120) 
         ["height"]=> 
         int(90) 
        } 
        ["medium"]=> 
        array(3) { 
         ["url"]=> 
         string(48) "https://i.ytimg.com/vi/bdzxVW3zlZ0/mqdefault.jpg" 
         ["width"]=> 
         int(320) 
         ["height"]=> 
         int(180) 
        } 
        ["high"]=> 
        array(3) { 
         ["url"]=> 
         string(48) "https://i.ytimg.com/vi/bdzxVW3zlZ0/hqdefault.jpg" 
         ["width"]=> 
         int(480) 
         ["height"]=> 
         int(360) 
        } 
        ["standard"]=> 
        array(3) { 
         ["url"]=> 
         string(48) "https://i.ytimg.com/vi/bdzxVW3zlZ0/sddefault.jpg" 
         ["width"]=> 
         int(640) 
         ["height"]=> 
         int(480) 
        } 
        } 
        ["channelTitle"]=> 
        string(10) "nenbanogon" 
        ["tags"]=> 
        array(1) { 
        [0]=> 
        string(14) "YouTube editor" 
        } 
        ["categoryId"]=> 
        string(2) "24" 
        ["liveBroadcastContent"]=> 
        string(4) "none" 
        ["localized"]=> 
        array(2) { 
        ["title"]=> 
        string(32) "Leap of Faith Movie_Steve Martin" 
        ["description"]=> 
        string(82) "I created this video with the YouTube Video Editor (http://www.youtube.com/editor)" 
        } 
       } 
       ["status"]=> 
       array(5) { 
        ["uploadStatus"]=> 
        string(9) "processed" 
        ["privacyStatus"]=> 
        string(6) "public" 
        ["license"]=> 
        string(7) "youtube" 
        ["embeddable"]=> 
        bool(true) 
        ["publicStatsViewable"]=> 
        bool(true) 
       } 
       } 
      } 
      } 
      ["processed":protected]=> 
      array(0) { 
      } 
     } 

響應對象有一個「狀態」陣列,其中我可以過濾私人和不可嵌入視頻

["status"]=> 
    array(5) { 
     ["uploadStatus"]=> 
     string(9) "processed" 
     ["privacyStatus"]=> 
     string(6) "public" 
     ["license"]=> 
     string(7) "youtube" 
     ["embeddable"]=> 
     bool(true) 
     ["publicStatsViewable"]=> 
     bool(true) 
    } 

但我不能過濾視頻因版權原因而被封鎖。

這裏是類似的問題How do I filter videos from YouTube Data API v3

+0

你要過濾哪裏?客戶端或服務器? –

+0

我試圖在服務器端進行過濾。使用此[鏈接](https://developers.google.com/youtube/v3/docs/search/list)文檔,但無法找到解決方法。 –

+0

服務器端代碼是什麼語言? PHP? –

回答

0

請嘗試使用safeSearch。

$videosResponse = $youtube->videos->listVideos('status, fileDetails, snippet, recordingDetails, topicDetails', array(
         'id' => $id, 
         'maxResults' => 1, 
         'part' => 'status,snippet', 
         'safeSearch' => 'strict', 
        )); 
相關問題