Skip to content

Example of Azure function deployment for gallery powered by public google photos albums

License

Notifications You must be signed in to change notification settings

mikeparcewski/gphotos-serverless

Repository files navigation

Google Photos Serverless

Based on on publicalbum.orgs google photos embed, this python serverless function lets you embed your google photos public albums in your website seamlessly by returning a json payload ready for whatever you can dream up.

What it does

Parses the HTML page returned from a public google photos album and returns the images as JSON. This allows you to manage you entire gallery within google photos (add/remove, order, etc...) and embed the gallery or use it within any application easily that supports a JSON payload.

You could do something similar using google API's, but the setup required seemed more than the 20 lines of code to do this, plus can embed this directly in HTML!

Service Response

This function, when provided a valid Google photos alibum ID, will return a json payload that contains an array of images from the album with their height/width.

  {
    "images": [
      {
        "src":"https://lh3.googleusercontent.com/-Z4_GTK5gw2ke5d9pH1H48SBA6DWp4FaGx1wYNap1U23A34CgNtc2mcw75MAJ3lP1R3w00nU_ftdurj7akXmhqYg7z6tMrepLj2N3tJc93fHUG5rfD6mqKaBGJ3ur17o6TvBHMII9Q=h988",
        "w":1500,
        "h":988
      },
      {
        "src":"https://lh3.googleusercontent.com/dwdOyD2zpcpfdV9QWvDt1i83LvOfEx0GE1jzy0TVHWqU9fq8FSW70YXykguDmeRWJW9ophqA8bcnYxBr68yS3fjHFp-8Vx6HSS-NQjq_FcZUCP__GiukzcJVhg44VWthiylleWEtMw=h800",
        "w":1400,
        "h":800
      }
    ]
  }

For my project I use this with react-stack-grid - https://github.com/tsuyoshiwada/react-stack-grid), which creates a modern scrolling gallery (see https://www.dragonflyoib.com/gallery fpr example)

PreRequisites

If you haven't ever deployed a function before to Azure, reccomend reading https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azurefunctions before you do this.

Getting Running

For the fastest setup, don’t checkout via command line. Instead, open VS Code and follow the following steps.

  • Clone directly in VS Code
    • Click on “Source Control” in the left column
      source control button
    • Get the link to clone this repo
      Getting the URL
    • Then, click "Clone Repository" and paste the clone url for this repo in entered box Cloning the Repo
  • Next, select python 3 environment when it pops up at the top of your screen
    Select Python
  • Finally, you’ll see a dialog in the bottom corner saying VS “detected Azure Function Project”, click “Yes” on it
    Initialize Function

Running locally

  • Click on the run/debug icon in the left navigation. You'll see the "RUN AND DEBUG" panel open to the right, click on the green play button.
    Run the Function
  • Grab the URL from the terminal window (bottom of IDE)
    Terminal Window
  • In your browser you will need the URL plus the google photos id we created in the last section.

If you’re building the app you want to embed this in locally, now is the time to start playing with it.

Deploying

  • Open azure panel by clicking on Azure icon in left nav
    Azure Icon
  • Expand "Local Project" under "Functions" and then expand "Functions"
    Select Project
  • Click on the cloud icon to deploy
    Cloud Icon
  • Click "Create new Function App in Azure" (not the advanced version)
    Create Function
  • Enter name for the function and then hit enter
    Enter Name
  • Choose the runtime stack (3.9)
    Select Project
  • Choose region
    Choose Region

This will take a few

Using Live Function

  • Open the Azure panel again
    Azure Icon
  • Expand “Azure Subscription”, expand the function name (e.g. GooglePhotosGallery), and finally expand "Functions" under it.
    Expand Subscription
  • Finally click “Copy Function URL” for the live URL
    Copy Function URL

Honestly, it took me longer to write the README then to develop/deploy the function, but if you're like me and get bored with the standard "Hello World" apps or actually (like me) need this functionality why not :)

About

Example of Azure function deployment for gallery powered by public google photos albums

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages