Skip to content

duffpl/google-photos-api-client

Repository files navigation

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

About

Yet Another Google Photos API Client

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages