Yet Another Google Photos API Client
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.
List of implemented endpoints
Based on https://developers.google.com/photos/library/reference/rest/v1/albums
- albums.addEnrichment
- albums.batchAddMediaItems
- albums.batchRemoveMediaItems
- albums.create
- albums.get
- albums.list
- albums.patch
- albums.share
- albums.unshare
- mediaItems.batchCreate
- mediaItems.batchGet
- mediaItems.get
- mediaItems.list
- mediaItems.patch
- mediaItems.search
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)
...
- functional tests that'll check if API didn't change
- unit tests
- implement all endpoints (almost there)
- add validation to request options structs