db = $wpdb; $this->api_yt_key = get_option('ave-yt-api'); $this->ave_loadHooks(); } /* Creating the hooks for the functions below */ function ave_loadHooks(){ add_action('admin_menu', array($this,'ave_videoSearch')); add_action('wp_ajax_ave_loadVideos',array($this,'ave_loadVideos')); add_action('wp_ajax_nopriv_ave_loadVideos',array($this,'ave_loadVideos')); } /* Settings up admin menu for ave video search */ function ave_videoSearch(){ add_menu_page("A.V.E VIDEO SEARCH", "A.V.E VIDEO SEARCH", "administrator", "ave_search", array($this,"ave_searchPanel"), plugins_url( '../img/LOGO_AVE.png', __FILE__ )); } /* loading the html markup for search panel. */ function ave_searchPanel(){ require_once AVE_PLUGIN_DIR.'/inc/views/search_panel.php'; } /* @keyword require the keyword to search for videos on two different platforms */ function ave_loadVideos(){ $keyword = $_REQUEST['s']; $max_ = $_REQUEST['max']; $order = $_REQUEST['order']; $params = array( 'q' => $keyword, 'maxResults' => $max_, 'order'=>$order, ); require_once AVE_PLUGIN_DIR.'/inc/youtube/Google/autoload.php'; //require_once 'Google/Service/YouTube.php'; /* * Set $DEVELOPER_KEY to the "API key" value from the "Access" tab of the * {{ Google Cloud Console }} <{{ https://cloud.google.com/console }}> * Please ensure that you have enabled the YouTube Data API for your project. */ $DEVELOPER_KEY = $this->api_yt_key; $client = new Google_Client(); $client->setDeveloperKey($DEVELOPER_KEY); // Define an object that will be used to make all API requests. $youtube = new Google_Service_YouTube($client); try { // Call the search.list method to retrieve results matching the specified // query term. $searchResponse = $youtube->search->listSearch('id,snippet',$params); $videos = ''; $channels = ''; $playlists = ''; // Add each result to the appropriate list, and then display the lists of // matching videos, channels, and playlists. foreach ($searchResponse['items'] as $searchResult) { switch ($searchResult['id']['kind']) { case 'youtube#video': $title = str_replace("'","\'",$searchResult['snippet']['title']); ?>
<?=$searchResult['snippet']['title'];?>
Api Error: %s

', htmlspecialchars($e->getMessage())); } catch (Google_Exception $e) { echo sprintf('

An client error occurred: %s

', htmlspecialchars($e->getMessage())); } exit(); } }