Youtube API v3 - 获取视频网址

时间:2014-04-21 13:58:53

标签: php video youtube

我正在通过Youtube API v3将视频上传到我的频道。我想自动将这些视频嵌入我的网站,所以我想在上传后立即保存我的数据库中的视频链接或嵌入代码。

以这种方式上传视频时,视频资源对象是返回网络,具有以下特征:

https://developers.google.com/youtube/v3/docs/videos

但是当我尝试检索这些数据时,完全不完整。

我做错了什么?有没有其他方法来获得至少视频网址?因为在视频对象引用中它没有出现这种特性。

这是返回对象的var_dump:

object(Google_Service_YouTube_Video)#639 (35) { ["ageGatingType":protected]=> string(37) "Google_Service_YouTube_VideoAgeGating" ["ageGatingDataType":protected]=> string(0) "" ["contentDetailsType":protected]=> string(42) "Google_Service_YouTube_VideoContentDetails" ["contentDetailsDataType":protected]=> string(0) "" ["conversionPingsType":protected]=> string(43) "Google_Service_YouTube_VideoConversionPings" ["conversionPingsDataType":protected]=> string(0) "" ["etag"]=> string(57) ""OilNCqKLXpFjeQ5CI-_BZqeMuCo/YPCGdIxr3w1vom2ktjPNSjPvFz4"" ["fileDetailsType":protected]=> string(39) "Google_Service_YouTube_VideoFileDetails" ["fileDetailsDataType":protected]=> string(0) "" ["id"]=> string(11) "-RbO_K6wgt4" ["kind"]=> string(13) "youtube#video" ["liveStreamingDetailsType":protected]=> string(48) "Google_Service_YouTube_VideoLiveStreamingDetails" ["liveStreamingDetailsDataType":protected]=> string(0) "" ["monetizationDetailsType":protected]=> string(47) "Google_Service_YouTube_VideoMonetizationDetails" ["monetizationDetailsDataType":protected]=> string(0) "" ["playerType":protected]=> string(34) "Google_Service_YouTube_VideoPlayer" ["playerDataType":protected]=> string(0) "" ["processingDetailsType":protected]=> string(45) "Google_Service_YouTube_VideoProcessingDetails" ["processingDetailsDataType":protected]=> string(0) "" ["projectDetailsType":protected]=> string(42) "Google_Service_YouTube_VideoProjectDetails" ["projectDetailsDataType":protected]=> string(0) "" ["recordingDetailsType":protected]=> string(44) "Google_Service_YouTube_VideoRecordingDetails" ["recordingDetailsDataType":protected]=> string(0) "" ["snippetType":protected]=> string(35) "Google_Service_YouTube_VideoSnippet" ["snippetDataType":protected]=> string(0) "" ["statisticsType":protected]=> string(38) "Google_Service_YouTube_VideoStatistics" ["statisticsDataType":protected]=> string(0) "" ["statusType":protected]=> string(34) "Google_Service_YouTube_VideoStatus" ["statusDataType":protected]=> string(0) "" ["suggestionsType":protected]=> string(39) "Google_Service_YouTube_VideoSuggestions" ["suggestionsDataType":protected]=> string(0) "" ["topicDetailsType":protected]=> string(40) "Google_Service_YouTube_VideoTopicDetails" ["topicDetailsDataType":protected]=> string(0) "" ["data":protected]=> array(2) { ["snippet"]=> array(9) { ["publishedAt"]=> string(24) "2014-04-21T13:48:06.000Z" ["channelId"]=> string(24) "UCg1bpF8UvsR8iEtZp0X82mw" ["title"]=> string(3) "vdz" ["description"]=> string(8) "vdavvvvv" ["thumbnails"]=> array(3) { ["default"]=> array(1) { ["url"]=> string(47) "https://i1.ytimg.com/vi/-RbO_K6wgt4/default.jpg" } ["medium"]=> array(1) { ["url"]=> string(49) "https://i1.ytimg.com/vi/-RbO_K6wgt4/mqdefault.jpg" } ["high"]=> array(1) { ["url"]=> string(49) "https://i1.ytimg.com/vi/-RbO_K6wgt4/hqdefault.jpg" } } ["channelTitle"]=> string(7) "Twinkle" ["tags"]=> array(2) { [0]=> string(4) "tag1" [1]=> string(4) "tag2" } ["categoryId"]=> string(2) "22" ["liveBroadcastContent"]=> string(4) "none" } ["status"]=> array(5) { ["uploadStatus"]=> string(8) "uploaded" ["privacyStatus"]=> string(6) "public" ["license"]=> string(7) "youtube" ["embeddable"]=> bool(true) ["publicStatsViewable"]=> bool(true) } } ["processed":protected]=> array(0) { } }

1 个答案:

答案 0 :(得分:0)

执行请求时出错。我从示例中获取了代码:

$insertRequest = $youtube->videos->insert("status,snippet", $video);

“insert”方法的第一个参数,定义视频对象的哪些部分将被修改,以及您希望在响应中检索哪些部分。

所以解决方案正在改变:

$insertRequest = $youtube->videos->insert("status,snippet,player", $video);