Skip to content

Instantly share code, notes, and snippets.

@ultimateprogramer
Created July 5, 2017 17:47
Show Gist options
  • Select an option

  • Save ultimateprogramer/258ad19aae2a5a3aa9e2c6deb29f951c to your computer and use it in GitHub Desktop.

Select an option

Save ultimateprogramer/258ad19aae2a5a3aa9e2c6deb29f951c to your computer and use it in GitHub Desktop.
Using Client Secrets with Google API PHP
<?php
require_once __DIR__.'/vendor/autoload.php';
// For PHP you will need to define GOOGLE_APPLICATION_CREDENTIALS environment variable and point it to the path of the file
// You do not need to do this for Google App Engine
putenv('GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json');
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
// Sample call done to the SQL Admin
$sqladmin = new Google_Service_SQLAdmin($client);
$response = $sqladmin->instances
->listInstances('examinable-example-123')->getItems();
echo json_encode($response) . "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment