require_once 'vendor/autoload.php'; $client = new Google_Client(); $client->setAuthConfig('credentials.json'); $client->addScope(Google_Service_Drive::DRIVE); $drive = new Google_Service_Drive($client); $results = $drive->files->listFiles(array( 'q' => "mimeType='image/jpeg'", )); foreach ($results->files as $file) { printf("%s (%s)\n", $file->name, $file->mimeType); }
require_once 'vendor/autoload.php'; $client = new Google_Client(); $client->setAuthConfig('credentials.json'); $client->addScope(Google_Service_Sheets::SPREADSHEETS_READONLY); $service = new Google_Service_Sheets($client); $spreadsheetId = 'YOUR_SPREADSHEET_ID'; $range = 'Sheet1!A1:C3'; $response = $service->spreadsheets_values->get($spreadsheetId, $range); $values = $response->getValues(); if (empty($values)) { print "No data found.\n"; } else { foreach ($values as $row) { printf("%s, %s, %s\n", $row[0], $row[1], $row[2]); } }In this example, we create a new instance of Google_Client and set the authentication configuration file path. Then we add the scope of the Sheets API and create a new instance of the Google_Service_Sheets class, passing in the client instance. We specify the ID of the spreadsheet and the range of cells to retrieve. We use the get method to retrieve the data and then loop through the result to print out each row of data. Both of these examples use the Google API PHP Client library.