public static function getYouTubeService($clientId, $clientSecret, $accessToken) { if (!is_null(self::$_youtubeService)) { return self::$_youtubeService; } $client = self::getGoogleClient($clientId, $clientSecret); $accessTokenObject = json_decode($accessToken); if (isset($accessTokenObject->refresh_token)) { $client->refreshToken($accessTokenObject->refresh_token); } else { $client->setAccessToken($accessToken); } $service = new Google_YouTubeService($client); self::$_youtubeService = $service; return $service; }
protected function syncPlaylists($videoId, KalturaYouTubeDistributionJobProviderData $providerData) { $fieldValues = unserialize($providerData->fieldValues); $youtubeChannel = isset($fieldValues[KalturaYouTubeDistributionField::VIDEO_CHANNEL]) ? $fieldValues[KalturaYouTubeDistributionField::VIDEO_CHANNEL] : null; $newVideoPlaylists = isset($fieldValues[KalturaYouTubeDistributionField::PLAYLISTS]) ? $fieldValues[KalturaYouTubeDistributionField::PLAYLISTS] : null; $clientId = $providerData->googleClientId; $clientSecret = $providerData->googleClientSecret; $tokenData = $providerData->googleTokenData; if (!$newVideoPlaylists && !$tokenData) { // no playlists and token was not setup, do nothing return $providerData->currentPlaylists; } if (!$youtubeChannel) { KalturaLog::err('YouTube channel was not found'); return $providerData->currentPlaylists; } if (!$videoId) { KalturaLog::err('No video id'); return $providerData->currentPlaylists; } $youtubeService = YouTubeDistributionGoogleClientHelper::getYouTubeService($clientId, $clientSecret, $tokenData); $playlistSync = new YouTubeDistributionPlaylistsSync($youtubeService); $currentPlaylists = $playlistSync->sync($youtubeChannel, $videoId, $providerData->currentPlaylists, $newVideoPlaylists); return $currentPlaylists; }