Google API Laravel

How can we setup the Google APIs Client Library in Laravel 10?

Setting up the Google APIs Client Library and access using Service Account in Laravel involves several steps. This library allows you to integrate various Google APIs, such as Google Drive, Google Sheets, etc., into your Laravel application. Here’s a step-by-step guide to help you set it up:

Note: Before you begin, make sure you have Composer installed and your Laravel project is up and running.

Create a New Laravel Project (Optional):

Install Google API Client Library:

Use Composer to install the Google APIs Client Library

Create Google API Project and Get Credentials:

Enable the Required API:

  • In the Cloud Console, navigate to the “APIs & Services” > “Library” section.
  • Search for the API you want to use (e.g., Google Sheets, Google Drive) and enable it for your project.

Create a Service Account:

  • In the Cloud Console, navigate to the “APIs & Services” > “Credentials” section.
  • Click on “Create credentials” and select “Service account key.”
  • Follow the prompts to create a new service account. Give it a name and assign it the necessary permissions based on the API you’re using (e.g., Editor or Viewer access).
  • Download the JSON key file for the service account. This file will be used in your Laravel project.

More details google developers console to generate service-account credentials.

Upload your service account json file to “storeage/app/public/service-account.json” directory.

Configure Laravel Environment:

Open your Laravel project’s .env file and add the following lines, replacing the placeholders with your actual credentials:

Assign google Service Account config:

Create Routes and Controllers:
Test Your Application:

Access the application in your browser and navigate to the route to get list of all files and folder.