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: "xxx@eguevara-books.iam.gserviceaccount.com",
PrivateKey: []byte(data),
Scopes: []string{
"https://www.googleapis.com/auth/books",
},
TokenURL: google.JWTTokenURL,
Subject: "xxx@gmail.com",
}
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)
}