Пример #1
0
 /**
  * Init all the youtube client service stuff.
  *
  * Instead of instantiating the service in the constructor, we delay
  * it until really neeed because it's really memory hungry (2MB). That
  * way the editor or any other artifact requiring repository instantiation
  * can do it in a cheap way. Sort of lazy loading the plugin.
  */
 private function init_youtube_service()
 {
     global $CFG;
     if (!isset($this->service)) {
         require_once $CFG->libdir . '/google/lib.php';
         $this->client = get_google_client();
         $this->client->setDeveloperKey($this->apikey);
         $this->client->setScopes(array(Google_Service_YouTube::YOUTUBE_READONLY));
         $this->service = new Google_Service_YouTube($this->client);
     }
 }
Пример #2
0
 /**
  * Constructor.
  *
  * @param int $repositoryid repository instance id.
  * @param int|stdClass $context a context id or context object.
  * @param array $options repository options.
  * @param int $readonly indicate this repo is readonly or not.
  * @return void
  */
 public function __construct($repositoryid, $context = SYSCONTEXTID, $options = array(), $readonly = 0)
 {
     parent::__construct($repositoryid, $context, $options, $readonly = 0);
     $callbackurl = new moodle_url(self::CALLBACKURL);
     $this->client = get_google_client();
     $this->client->setClientId(get_config('googledocs', 'clientid'));
     $this->client->setClientSecret(get_config('googledocs', 'secret'));
     $this->client->setScopes(array(Google_Service_Drive::DRIVE_READONLY));
     $this->client->setRedirectUri($callbackurl->out(false));
     $this->service = new Google_Service_Drive($this->client);
     $this->check_login();
 }
Пример #3
0
 /**
  * Init all the m27tube client service stuff.
  *
  * Instead of instantiating the service in the constructor, we delay
  * it until really neeed because it's really memory hungry (2MB). That
  * way the editor or any other artifact requiring repository instantiation
  * can do it in a cheap way. Sort of lazy loading the plugin.
  */
 private function init_m27tube_service()
 {
     global $CFG;
     if (!isset($this->service)) {
         require_once $CFG->dirroot . '/repository/m27tube/google/lib.php';
         require_once $CFG->dirroot . '/repository/m27tube/google/Google/Service/YouTube.php';
         $this->client = get_google_client();
         $this->client->setDeveloperKey($this->apikey);
         $this->client->setScopes(array(Google_Service_YouTube::YOUTUBE_READONLY));
         $this->service = new Google_Service_YouTube($this->client);
     }
 }
Пример #4
0
 private function initialize_oauth()
 {
     $redirecturi = new moodle_url(self::REDIRECTURL);
     $returnurl = new moodle_url('/portfolio/add.php');
     $returnurl->param('postcontrol', 1);
     $returnurl->param('id', $this->exporter->get('id'));
     $returnurl->param('sesskey', sesskey());
     $clientid = $this->get_config('clientid');
     $secret = $this->get_config('secret');
     // Setup Google client.
     $this->client = get_google_client();
     $this->client->setClientId($clientid);
     $this->client->setClientSecret($secret);
     $this->client->setScopes(array(Google_Service_Drive::DRIVE_FILE));
     $this->client->setRedirectUri($redirecturi->out(false));
     // URL to be called when redirecting from authentication.
     $this->client->setState($returnurl->out_as_local_url(false));
     // Setup drive upload service.
     $this->service = new Google_Service_Drive($this->client);
 }
Пример #5
0
 /**
  * Gets the youtube service object.
  *
  * @return Google_Service_YouTube
  */
 protected function get_service()
 {
     global $CFG;
     if (!($apikey = get_config('block_tag_youtube', 'apikey'))) {
         return false;
     }
     // Wrapped in an if in case we call different get_videos_* multiple times.
     if (!isset($this->service)) {
         require_once $CFG->libdir . '/google/lib.php';
         $client = get_google_client();
         $client->setDeveloperKey($apikey);
         $client->setScopes(array(Google_Service_YouTube::YOUTUBE_READONLY));
         $this->service = new Google_Service_YouTube($client);
     }
     return $this->service;
 }