This package provides a client for using the Google Photos API. Uses the original Google Photos package, that was provided by Google, and removed some time ago. On top of the old package has been extended some other features like uploads, including resumable uploads.
This project will maintain compatibility with the last two Go major versions published. Currently Go 1.12 and Go 1.13.
Construct a new Google Photos client, then use the various services on the client to access different parts of the Google Photos API. For example:
import "github.com/gphotosuploader/google-photos-api-client-go/lib-gphotos"
// httpClient is an authenticated http.Client. See Authentication below.
client := gphotos.NewClient(httpClient)
// get or create a Photos Album with the specified name.
album, err := GetOrCreateAlbumByName("my-new-album")
// upload an specified file to an existent Photos Album.
_, err := client.AddMediaItem(ctx, path, albumID)
NOTE: Using the context package, one can easily pass cancellation signals and deadlines to various services of the client for handling a request. In case there is no context available, then
context.Background()
can be used as a starting point.
The gphotos library does not directly handle authentication. Instead, when creating a new client, pass an http.Client
that can handle authentication for you. The easiest and recommended way to do this is using the golang.org/x/oauth2
library, but you can always use any other library that provides an http.Client
.
Access to the API requires OAuth client credentials from a Google developers project. This project must have the Library API enabled as described here.
import (
"golang.org/x/oauth2"
"github.com/gphotosuploader/google-photos-api-client-go/lib-gphotos"
)
func main() {
ctx := context.Background()
oc := oauth2Config := oauth2.Config{
ClientID: "... your application Client ID ...",
ClientSecret: "... your application Client Secret ...",
Endpoint: photos.Endpoint,
Scopes: photos.Scopes,
}
tc := oc.Client(ctx, "... your user Oauth Token ...")
client := gphotos.NewClient(tc)
// look for a Google Photos Album by name
album, _, err := client.AlbumByName(ctx, "my-album")
}
Note that when using an authenticated Client, all calls made by the client will include the specified OAuth token. Therefore, authenticated clients should almost never be shared between different users. See the oauth2 docs for complete instructions on using that library.
Google Photos imposes a rate limit on all API clients. The quota limit for requests to the Library API is 10,000 requests per project per day. The quota limit for requests to access media bytes (by loading a photo or video from a base URL) is 75,000 requests per project per day.
All media items uploaded to Google Photos using the API are stored in full resolution at original quality. They count toward the user’s storage.