I applied the Google API client correctly in my PHP application. I was able to connect to the service I wanted.
But now I want to check whether the API key entered by the user is really entered.
I looked around or at the methods exposed by the Google_Client () class, but I don't think I'm sure how to check this.
The following is the method in my class that the client creates:
private function client( $api_key ) { $client = new \Google_Client(); $client->setClassConfig( 'Google_Cache_File', 'directory', $this->cache_dir ); $client->setDeveloperKey( $api_key ); $client->setApplicationName( $this->name ); $client->setScopes( array( \Google_Service_Calendar::CALENDAR_READONLY ) ); $client->setAccessType( 'online' ); return $client; }
And I want to do another way to find out if the API key is really used or not ...
public function validate_api_key( $api_key ) { $client = $this->client( $api_key ); // What should I use here to check if $api_key is valid? if ( $client ) { return true; } return 'error'; }
Or do I need to connect to the service and then check if I have read access? But I believe that there is a simpler and better way to do this ...
source share