Laravel 5 + Google APIs Client Library


  1. Created a google app project
  2. Enabled Google+ API at your google project
  3. Created new Client ID
  4. Generated API Key
  5. Get service account name

You can find in this google link to do above steps.If you have already done those, you can start the following steps.


In your composer.json file, add

"require": {
 "google/apiclient": "1.0.*@beta"//This beta version is when I use, get updated version when you use


(My apiclient version is still beta, so I need to set minimum-stability to dev, but if your version is stable, you don’t need to change and skip to Step3)Find minimum-stability in your laravel project, and change to

"minimum-stability": "dev"


run >>>>composer update. After that, you will see google folder under yourapp>vendor folder.


In your composer.json file, add the following;

{ "autoload": 
     { "classmap": [ "vendor/google/apiclient/src/Google" ],


In your Create a new Client ID in Credentials, Select Service account and click on Create Client ID


In config folder, add google.php and add;

return [
    'app_name'          => 'your_app_name', 
    'client_id'         => 'your_client_id',
    'client_secret'     => 'your_client_secret',
    'api_key'           => 'your_api_key',
    'service_account_name' => 'your_service_account_name'


Create app>Services>Google.php file and then add the following code;

use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Config;

class Google {

    protected $client;

    protected $service;

    function __construct() {
        /* Get config variables */
        $client_id = Config::get('google.client_id');
        $service_account_name = Config::get('google.service_account_name');
        $key = Config::get('google.api_key');//you can use later

        $this->client = new \Google_Client();
        $this->service = new \Google_Service_Books($this->client);//Test with Books Service        

    public function getBooks(){
        $optParams = array('filter' => 'free-ebooks');
        $results = $this->service->volumes->listVolumes('Henry David Thoreau', $optParams);



In HomeController, modify index function

public function index(Google $google)
    $result = $google->getBooks();



One thought on “Laravel 5 + Google APIs Client Library

  1. hi lex!

    im current working with google api, youtube data api to be exact and i followed your instruction but still, i got this error,
    “FatalErrorException in Google.php line 20:
    Class ‘eyevid\Services\Google_Client’ not found”

    i tried youtube data api documentation php examples but in plain php, i saved it in public folder and i used xampp to run it. and it works. now,i transfer it in controller and i followed your intructions and still, have this error.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s