tipoff/laravel-google-api

Laravel package for interacting with Google APIs.

Fund package maintenance!
tipoff

Installs: 40 185

Dependents: 4

Suggesters: 0

Security: 0

Stars: 0

Watchers: 5

Forks: 0

2.1.3 2021-05-06 23:57 UTC

README

Latest Version on Packagist Tests Total Downloads

This is where your description should go.

Installation

You can install the package via composer:

composer require tipoff/laravel-google-api

You can publish the config file with:

php artisan vendor:publish --provider="Tipoff\GoogleApi\GoogleApiServiceProvider" --tag="google-api-config"

Add the following variables to your .env file and set them based on the contents of the client_secret.json file you obtained from Google.

GOOGLE_CLIENT_ID=
GOOGLE_PROJECT_ID=
GOOGLE_CLIENT_SECRET=
GOOGLE_REDIRECT_URIS=
GOOGLE_JAVASCRIPT_ORIGINS=

GOOGLE_API_KEY=

You can use the | character to separate multiple strings in the GOOGLE_REDIRECT_URIS and GOOGLE_JAVASCRIPT_ORIGINS settings.

Obtain an API access token from Google and insert it into the keys table, giving it an identifying slug for the next step. (Make sure that the value field contains your token formatted as valid JSON.)

Set the value of GOOGLE_ACCESS_TOKEN_SLUG in your .env file to the name of the slug in your keys table entry.

Note: If you need to customize the client secret fields or access token value on a service-by-service basis, you may do so by setting values in your .env file for the service-specific values found in config/google-api.php. (For example, YOUTUBE_CLIENT_ID.)

If you do not set service-specific values, it will default to the options set above for each service.

Models

We include the following models:

List of Models

  • GMB Account
  • Key

For each of these models, this package implements an authorization policy that extends the roles and permissions approach of the tipoff/authorization package. The policies for each model in this package are registered through the package and do not need to be registered manually.

The models also have Laravel Nova resources in this package and they are also registered through the package and do not need to be registered manually.

Usage

// Get access token.
$accessToken = GoogleOauth::accessToken('search-console');

// Set access token.
$googleServices = app(GoogleServices::class)->setAccessToken($accessToken);

// Access services.
$searchConsole = $googleServices->searchConsole();
$myBusiness = $googleServices->myBusiness();
$youtube = $googleServices->youtube();
$youtubeAnalytics = $googleServices->youtubeAnalytics();
$analytics = $googleServices->analytics();
$place = $googleServices->places();

Note:

  • The Google Places service makes use of a third-party wrapper to access the Places API. Documentation on available methods for it is available here.
  • The Google Search Console service makes use of a third-party wrapper to access the Laravel Search Console. Documentation on available methods for it is available here.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.