Skip to content


Folders and files

Last commit message
Last commit date

Latest commit



89 Commits

Repository files navigation


PHP add-on for nanogallery2 for accessing Google Photos content.

Based on the Google Photos API.
Supported content: albums and photos (not videos).
Please note that the Google Photos API has a limit of 10.000 requests per day.



This app is delivered AS-IS, changes on Google side may break it without any warning.
Use at your own risk.


▶️ Upgrading from NANOGP to NANOGP2

The API used by nanogp is depreciated by Google and will be turned off on march 2019. A new API is available but the usage is not compatible with the depreciated one.

Migration - step by step:
  1. Install nanogp2 in a new folder (do not install over nanogp)
  2. Configure nanogp2
  3. update nanogallery2 settings in your HTML pages:
    • point google2URL to the new nanogp2 URL, e.g.: 'google2URL': 'https://YOUR_WEB_SERVER/nanogp2/nanogp2.php'
    • album's IDs have changed, update the value of the album parameter, if you use it.


▶️ Installation

➖ Pre-requisites:
  • Web server with PHP version > 5.4+
  • Cannot be run on localhost
  • nanogallery2 v2.4.1
➖ Installation procedure
  • Create a folder named nanogp2 on your web server.
  • Copy the content of the dist folder in this folder.

You should have a structure with these folders, files and permissions:

     nanogp2              [rwx---r-x]
     │   authorize.php    [rw----r--]
     │   check.php        [rw----r--]
     │   nanogp2.php      [rw----r--]
     └─── admin           [rwx---r-x]
         │   .htaccess    [rw----r--]
         │   config.php   [rw----r--]
         │   tools.php    [rw----r--]
         └─── users       [rwx---r-x]
             │   xxxx     [rwx---r-x]
             │   ...      [rwx---r-x]



▶️ Enable Google API - Google API Console

  1. For your nanogp2 installation, you need to register your instance using the Google API Console.
    • create a new project called nanogallery2gp-YOUR-INSTANCE-NAME (the project name should be unique, so replace YOUR-INSTANCE-NAME with the name of your own instance)
    • create a OAuth consent screen
      • application name: nanogallery2gp-YOUR-INSTANCE-NAME
      • set the support email
      • add scopes: email, profile, openid
      • authorized domains: name of the domain where your nanogp2 is installed
    • create credentials kind OAuth Client ID
      • application type: Web application
      • name: nanogallery2gp-YOUR-INSTANCE-NAME
      • Authorized redirect URIs: set the full path to your authorize.php (once with http, and once with https)
  2. Google then provides information you'll need later, such as a client ID and a client secret.
  3. Activate the Google Photos Library API in the Google API Console. (If the API isn't listed in the API Console, then skip this step).


▶️ Configuration

Settings are defined in admin/config.php:

  $cfg_client_id     = 'yyy';
  $cfg_client_secret = 'zzz';
  $albums_filter     = ['sauvegarde', 'backup'];

Client ID ($cfg_client_id) and client secret ($cfg_client_secret) can be obtained from the Google API Console.
$albums_filter is used to filter albums out. Albums with a title containing one of the string will not be displayed.

Client secret should never be shared ❗ . Only your nanogp2 installation should access it.


▶️ User authorization


➖ Grant authorization

  1. Once the settings are defined, you need to grant authorization to nanogp2 to access your Google Photos account.
  2. Use a browser and open the authorize.php page: https://YOUR_WEB_SERVER/nanogp2/authorize.php
  3. Google displays a consent screen, asking you to authorize your instance of nanogp2 to request some of your data. If you get a warning message This app isn't verified, you need to display the advanced options to grant authorization to your nanogp2 instance.

At the end of the process:

  • your user-ID is displayed. This value should be set in your nanogallery2's options (userID).
  • a folder named like your user-ID has been created in nanogp2/admin/users. It contains the files profile.txt, token_a.txt and token_r.txt. Never delete these files.

(if you've granted authorization and if you want to grant authorization again, follow the steps from the section Manually revoke authorization).


➖ nanogallery2 parameters

After authorization is granted, from your browser, open the authorize.php page again to display the parameters for nanogallery2.


➖ Security

The admin folder should only be accessible to your PHP applications, and not from a browser.
For this, you may for example put an .htaccess file containing deny from all.


➖ Manually revoke authorization



All your photos albums can by accessed by nanogp2. This may be misused by malicious people.
Please use nanogp2 only with a Google Photos account which does not contain any personal or privat data.

  • configure the option $albums_filter to protect your privacy


▶️ Retrieve one user's list of albums

Command to generate a report with the list of album's names and IDs for one specific user:

Replace YOUR_WEB_SERVER and USER_ID with the correct values for your nanogp2 instance.

For security reason, the report is generated in the user's folder on the server (nanogp2/admin/users/USER_ID/google_photos_data.txt).

Note: this report is only for your information and is not used by nanogallery2.