2015-10-20 57 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', 
        )); 
相关问题