2017 © Pedro Peláez
 

library laravel-google-photos

Google Photos API for Laravel

image

revolution/laravel-google-photos

Google Photos API for Laravel

  • Sunday, June 24, 2018
  • by revolution
  • Repository
  • 1 Watchers
  • 2 Stars
  • 81 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 12 Versions
  • 31 % Grown

The README.md

Google Photos API for Laravel

Maintainability Test Coverage, (*1)

https://developers.google.com/photos/, (*2)

Requirements

  • PHP >= 8.2
  • Laravel >= 11.0

Versioning

  • Basic : semver
  • Drop old PHP or Laravel version : +0.1. composer should handle it well.
  • Support only latest major version (master branch), but you can PR to old branches.

Installation

composer require revolution/laravel-google-photos

Get API Credentials

from https://developers.google.com/console, (*3)

  • Enable Photos Library API and Google Photos Picker API. Be careful not to select Google Picker API as it is different from the Photos Picker API.
  • Create OAuth2.0 client id.

config/google.php

    'client_id'        => env('GOOGLE_CLIENT_ID', ''),
    'client_secret'    => env('GOOGLE_CLIENT_SECRET', ''),
    'redirect_uri'     => env('GOOGLE_REDIRECT', ''),
    'scopes'           => [
        'https://www.googleapis.com/auth/photoslibrary.appendonly',
        'https://www.googleapis.com/auth/photoslibrary.readonly.appcreateddata',
        'https://www.googleapis.com/auth/photoslibrary.edit.appcreateddata',
        'https://www.googleapis.com/auth/photospicker.mediaitems.readonly',
    ],
    'access_type'      => 'offline',
    'approval_prompt'  => 'force',
    'prompt'           => 'consent', //"none", "consent", "select_account" default:none

Currently, you can only access files uploaded via the API., (*4)

'access_type' => 'offline' is required to obtain a refresh token., (*5)

Google Photos API does not support Service Account., (*6)

config/service.php for Socialite

    'google' => [
        'client_id'     => env('GOOGLE_CLIENT_ID', ''),
        'client_secret' => env('GOOGLE_CLIENT_SECRET', ''),
        'redirect'      => env('GOOGLE_REDIRECT', ''),
    ],

.env

GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
GOOGLE_REDIRECT=

Usage example

Currently, Google Photos Library API only allows access to files uploaded via API, so it is difficult to use it freely., (*7)

Using it with someone else's account requires review., (*8)

It is still possible to upload one-way, so it is best to only use the upload function to your own account., (*9)

  1. Enable the Photos Library API in the Google console and add yourself as a test user.
  2. Get refresh_token by Socialite. Save it in the users table.
  3. Upload the photo.
// Command or etc

use App\Models\User;
use Illuminate\Support\Facades\Storage;
use Revolution\Google\Photos\Facades\Photos;

Photos::withToken(User::find(1)->refresh_token);

with(Photos::upload(Storage::get('test.png'), 'test.png'), function (string $token) {
    Photos::batchCreate([$token]);
});

PhotosLibraryClient

This package depends on google/photos-library and automatically delegates to the methods on PhotosLibraryClient., (*10)

  • https://github.com/google/php-photoslibrary/blob/main/src/Google/Photos/Library/V1/PhotosLibraryClient.php
  • https://github.com/google/php-photoslibrary/blob/main/src/Google/Photos/Library/V1/Gapic/PhotosLibraryGapicClient.php
use Revolution\Google\Photos\Facades\Photos;

$album = Photos::withToken('token')->updateAlbumTitle($albumId, $newTitle);

PagedListResponse

listMediaItems() and listAlbums() return a PagedListResponse, which is basically used with foreach., (*11)

  • https://github.com/googleapis/gax-php/blob/main/src/PagedListResponse.php
use Revolution\Google\Photos\Facades\Photos;
use Google\ApiCore\PagedListResponse;

$items = Photos::withToken('token')->listMediaItems();

foreach ($items as $item){
    dump($item->getBaseUrl());
}

Create new album

PhotosLibraryResourceFactory has various creation methods., (*12)

  • https://github.com/google/php-photoslibrary/blob/main/src/Google/Photos/Library/V1/PhotosLibraryResourceFactory.php
use Google\Photos\Library\V1\PhotosLibraryResourceFactory;
use Revolution\Google\Photos\Facades\Photos;

$newAlbum = Photos::withToken('token')->createAlbum(PhotosLibraryResourceFactory::album('title'));

dump($newAlbum->getId());
dump($newAlbum->getTitle());

Picker

Picker API, (*13)

LICENSE

MIT, (*14)

The Versions

24/06 2018

dev-master

9999999-dev

Google Photos API for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by kawax

laravel google photos

24/06 2018

1.0.9

1.0.9.0

Google Photos API for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by kawax

laravel google photos

22/05 2018

1.0.8

1.0.8.0

Google Photos API for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by kawax

laravel google photos

17/05 2018

1.0.7

1.0.7.0

Google Photos API for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by kawax

laravel google photos

15/05 2018

1.0.6

1.0.6.0

Google Photos API for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by kawax

laravel google photos

15/05 2018

1.0.5

1.0.5.0

Google Photos API for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by kawax

laravel google photos

15/05 2018

dev-develop

dev-develop

Google Photos API for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by kawax

laravel google photos

15/05 2018

1.0.4

1.0.4.0

Google Photos API for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by kawax

laravel google photos

13/05 2018

1.0.3

1.0.3.0

Google Photos API for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by kawax

laravel google photos

13/05 2018

1.0.2

1.0.2.0

Google Photos API for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by kawax

laravel google photos

13/05 2018

1.0.1

1.0.1.0

Google Photos API for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by kawax

laravel google photos

12/05 2018

1.0.0

1.0.0.0

Google Photos API for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by kawax

laravel google photos