문제

I am uploading videos to my channel via Youtube API v3. I would like to embedd these videos in my site automatically, so I want to save either the video link or the embed code in my DataBase, just after the upload.

When a video is uploaded this way, a video resource object is returnet, with these characteristics:

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

But when I try to retrieve this data, is totally uncomplete.

What am I doing wrong? Is there any other way to get at least the video URL? Because in the video object reference it does not appear this characteristic.

This is a var_dump of the returned object:

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) { } }
도움이 되었습니까?

해결책

The error was when doing the request. I took the code from the example:

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

The first parameter of "insert" method, defines what parts of the video object will be modified and what parts do you want to be retrieved in the response.

So the solution was changing to this:

$insertRequest = $youtube->videos->insert("status,snippet,player", $video);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top