go-books is a Go client library for accessing Google Books Annotations API.
https://developers.google.com/apis-explorer/?hl=en_US#s/books/v1/
import "github.com/eguevara/go-books"
OAuth2 http client is required to to access Google Books API on behalf of a user.
data, err := ioutil.ReadFile("pemFile")
if err != nil {
log.Fatal(err)
}
conf := &jwt.Config{
Email: "[email protected]",
PrivateKey: []byte(data),
Scopes: []string{
"https://www.googleapis.com/auth/books",
},
TokenURL: google.JWTTokenURL,
Subject: "[email protected]",
}
client := conf.Client(oauth2.NoContext)
client, err := books.New(oauthClient)
if err != nil {
log.Fatalf("http: error %v", err)
}
opts := &books.AnnotationsListOptions{
VolumeID: "volumeId",
ContentVersion: "version",
LayerID: "notes",
Source: "app",
Fields: "items(layerId,selectedText,volumeId),totalItems",
}
list, _, err := client.Annotations.List(opts)
if err != nil {
log.Fatalf("error in list(): %v ", err)
}