MDL-67733 repository_youtube: Use new Google API Client integration

This commit is contained in:
Huong Nguyen
2025-12-17 07:44:46 +07:00
parent 6be7a552ce
commit e873d7cb52
+10 -7
View File
@@ -22,6 +22,10 @@
* @copyright 2010 Dongsheng Cai {@link http://dongsheng.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use Google\Client;
use Google\Service\YouTube;
require_once($CFG->dirroot . '/repository/lib.php');
/**
@@ -45,13 +49,13 @@ class repository_youtube extends repository {
/**
* Google Client.
* @var Google_Client
* @var Client
*/
private $client = null;
/**
* YouTube Service.
* @var Google_Service_YouTube
* @var YouTube
*/
private $service = null;
@@ -90,11 +94,10 @@ class repository_youtube extends repository {
global $CFG;
if (!isset($this->service)) {
require_once($CFG->libdir . '/google/lib.php');
$this->client = get_google_client();
$this->client = new core\google_api_client();
$this->client->setDeveloperKey($this->apikey);
$this->client->setScopes(array(Google_Service_YouTube::YOUTUBE_READONLY));
$this->service = new Google_Service_YouTube($this->client);
$this->client->setScopes([YouTube::YOUTUBE_READONLY]);
$this->service = new YouTube($this->client);
}
}
@@ -228,7 +231,7 @@ class repository_youtube extends repository {
'source' => $source,
);
}
} catch (Google_Service_Exception $e) {
} catch (\Google\Service\Exception $e) {
// If we throw the google exception as-is, we may expose the apikey
// to end users. The full message in the google exception includes
// the apikey param, so we take just the part pertaining to the