'

Optional: Only required if using videos from Google Drive.

Directions: Go to the Google Developers Console, create a project, then enable the Drive API. Next go to the credentials section and create a new public API access key. Choose server key, then leave allowed IPs blank and click create. Copy and paste your new API key below.

', 'fields' => array( 'api_key' => array( 'name' => 'API Key', 'type' => 'text', 'description' => '' ) ) ); public static function register_provider( $providers ) { $providers[self::service_slug] = new self; return $providers; } // Regex strings public $regexes = array( '#(?:https?:)?//docs\.google\.com/(?:a/[^/]+/)?file/d/([A-Za-z0-9\-_]+)/preview#', // iFrame URL '#(?:https?:)?//video\.google\.com/get_player\?docid=([A-Za-z0-9\-_]+)#', // Flash URL '##', // Flash (YouTube player) ); // Thumbnail URL public function get_thumbnail_url( $id ) { // Get our API key $api_key = ( isset( $this->options['api_key'] ) && $this->options['api_key'] != '' ? $this->options['api_key'] : false ); if ( $api_key ) { $request = "https://www.googleapis.com/drive/v2/files/$id?fields=thumbnailLink&key=$api_key"; $response = wp_remote_get( $request ); if( is_wp_error( $response ) ) { $result = $this->construct_info_retrieval_error( $request, $response ); } else { $json = json_decode( $response['body'] ); if ( isset( $json->error ) ) { $result = new WP_Error( 'googledrive_info_retrieval', $json->error->message ); } else { $result = $json->thumbnailLink; $result = str_replace( '=s220', '=s480', $result ); } } } else { $result = new WP_Error( 'googledrive_api_key', __( 'You must enter an API key in the provider settings to retrieve thumbnails from Google Drive.', 'video-thumbnails' ) ); } return $result; } // Test cases public static function get_test_cases() { return array( array( 'markup' => '', 'expected' => 'https://lh3.googleusercontent.com/QL3d7Wh7V_qcXnMpXT6bio77RS0veyCZZ0zQbMX6gd-qH7aeIXBkXlcSJVDEyftiiA=s480', 'expected_hash' => '3bc674d8d77b342e633ab9e93e345462', 'name' => __( 'iFrame Embed', 'video-thumbnails' ) ), array( 'markup' => '', 'expected' => 'https://lh6.googleusercontent.com/WeOdCsaplJ3am25To1uLZiVYkyrilAQ5rxzhjnyyFc5GAF4QeCF1eq3EMpbP7O5dFg=s480', 'expected_hash' => 'f120755bbd1d35e381cb84a829ac0dfa', 'name' => __( 'iFrame Embed (Apps account)', 'video-thumbnails' ) ), array( 'markup' => '', 'expected' => 'https://lh3.googleusercontent.com/U_lqaX1o7E9iU75XwCrHZ4pdSi-Vch2F_GK5Ib7WAxgwKTvTl0kMHXm2GxKo1Pcp3Q=s480', 'expected_hash' => '31cf8e05f981c1beb6e04823ad54d267', 'name' => __( 'Flash Embed', 'video-thumbnails' ) ), array( 'markup' => '', 'expected' => 'https://lh5.googleusercontent.com/mHn5gESachhZHi-kbPCRbR6RVXZm3bR7oNNXL97LyYjpzV3Eqty71J2Waw0DPnXKKw=s480', 'expected_hash' => '2d0ad4881e4b38de0510a103d2f40dd1', 'name' => __( 'Flash Embed (YouTube player)', 'video-thumbnails' ) ), ); } } ?>