-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
34 lines (28 loc) · 1.11 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package main
import (
"context"
"fmt"
"log"
"github.com/awangga/gopi"
"google.golang.org/api/docs/v1"
"google.golang.org/api/option"
)
var apiscope = []string{"https://www.googleapis.com/auth/spreadsheets", "https://www.googleapis.com/auth/documents", "https://www.googleapis.com/auth/drive", "https://www.googleapis.com/auth/blogger", "https://www.googleapis.com/auth/gmail.send", "https://www.googleapis.com/auth/gmail.readonly"}
const jsonsecfile = "credentials.json"
const tokenfile = "token.json"
func main() {
client := gopi.GetClient(jsonsecfile, tokenfile, apiscope...)
ctx := context.Background()
srv, err := docs.NewService(ctx, option.WithHTTPClient(client))
if err != nil {
log.Fatalf("Unable to retrieve Docs client: %v", err)
}
// Prints the title of the requested doc:
// https://docs.google.com/document/d/195j9eDD3ccgjQRttHhJPymLJUCOUjs-jmwTrekvdjFE/edit
docId := "195j9eDD3ccgjQRttHhJPymLJUCOUjs-jmwTrekvdjFE"
doc, err := srv.Documents.Get(docId).Do()
if err != nil {
log.Fatalf("Unable to retrieve data from document: %v", err)
}
fmt.Printf("The title of the doc is: %s\n", doc.Title)
}