Socket
Book a DemoInstallSign in
Socket

github.com/duffpl/google-photos-api-client

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/duffpl/google-photos-api-client

v0.2.0
Source
Go
Version published
Created
Source

google-photos-api-client

Yet Another Google Photos API Client

Description

I needed Google Photos API client for one of my projects. Since Google removed auto-generated client for Go I've decided to create one. There are some other libraries floating around but wanted to give it a try on my own and I just didn't like using generated client from mirrored generated library.

I've tried to make client less complicated compared to generated/existing ones (hopefully).

It seems that API is pretty stable so I guess that client should be working in unforseen future too.

Besides basic API communication all methods have their async/sync wrappers for consuming results on the go and not caring about pagination.

Uploading media items has basic implementation - no partial/resumable uploads. To make life a bit easier there is method that allows batch uploading files specified by path into choosen album.

Error handling might be a bit flaky but should be OK.

godoc documentation

List of implemented endpoints

Albums

Based on https://developers.google.com/photos/library/reference/rest/v1/albums

Media items

Shared albums

Usage

Client requires prepared HTTP OAuth client. Example implementation using golang.org/x/oauth2/google:

func main() {
    credsConfig, _ := ioutil.ReadFile("google-api-credentials.json")
    oauthConfig, _ := google.ConfigFromJSON(
        credsConfig,
        "https://www.googleapis.com/auth/photoslibrary",
        "profile",
    )
    apiToken := &oauth2.Token{
        RefreshToken: "<< refresh token >>",
    }
    oauthHttpClient := oauthConf.Client(context.Background(), apiToken)
    apiClient := google_photos_api_client.NewApiClient(oauthHttpClient)
}

Resources can be accessed through their services in client. E.g.:

...
apiClient := google_photos_api_client.NewApiClient(oauthHttpClient)
items, err := apiClient.MediaItems.ListAll(nil, ctx)
albums, err := apiClient.Albums.ListAll(
    &google_photos_api_client.AlbumsListOptions{
        PageSize:                 20,
        ExcludeNonAppCreatedData: true,
    }, ctx)
...

To do

  • functional tests that'll check if API didn't change
  • unit tests
  • implement all endpoints (almost there)
  • add validation to request options structs

FAQs

Package last updated on 16 Sep 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.