$client = new Google_Client(); $client->setDeveloperKey('YOUR_APP_KEY_HERE'); $client->setDefer(true); // Build the API request $request = $client->getClient()->get('https://www.googleapis.com/youtube/v3/search', array( 'part' => 'snippet', 'q' => 'cats' )); // Execute the API request later $searchResponse = $request->execute();
$client = new Google_Client(); $client->setDeveloperKey('YOUR_APP_KEY_HERE'); $client->setDefer(true); $batch = new Google_Http_Batch($client); // Add API requests to batch $batch->add($client->getClient()->get('https://www.googleapis.com/youtube/v3/search', array( 'part' => 'snippet', 'q' => 'cats' ))); $batch->add($client->getClient()->get('https://www.googleapis.com/youtube/v3/search', array( 'part' => 'snippet', 'q' => 'dogs' ))); // Execute API requests in batch $searchResponses = $batch->execute();In this example, multiple YouTube API requests are added to a batch execution with `$batch->add()`. The batch requests are executed at the same time with `$batch->execute()`. The package library used in these examples is the Google API PHP Client library.