-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExportGdoc.go
70 lines (57 loc) · 1.23 KB
/
ExportGdoc.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// v1
// v2 start a text debug
// 10/1/22
//
//
package main
import (
"fmt"
"os"
gdrive "google/gdrive/gdriveApi"
)
func main() {
var gd gdrive.GdriveApiStruct
numArgs := len(os.Args)
if numArgs < 3 {
fmt.Println("error - insufficient comand line arguments!")
fmt.Printf(" usage is:\n %s docId mime\n", os.Args[0])
os.Exit(1)
}
docId := os.Args[1]
fmt.Println("Doc Id: ", docId)
mime := os.Args[2]
/*
mimeType, ok := gdrive.Gapp[mime]
if !ok {
fmt.Printf("error cvtMime: mime %s is not valid! \n", mime)
os.Exit(1)
}
fmt.Println("mimeType: ",mimeType)
*/
err := gd.Init()
if err != nil {
fmt.Println("error Init:", err)
os.Exit(1)
}
srv := gd.Svc
// docId := "1pdI_GFPR--q88V3WNKogcPfqa5VFOpzDZASo4alCKrE"
fil, err := srv.Files.Get(docId).Do()
if err != nil {
fmt.Println("error Get: Unable to find file!", err)
os.Exit(1)
}
filnam := fil.Name
fmt.Println("file name: ", filnam)
if !(len(filnam) >0) {
fmt.Println("erro no file name")
os.Exit(1)
}
// mimeType := "application/pdf"
err = gd.ExportFileById(docId, filnam, mime)
if err != nil {
fmt.Println("Unable to download document into app: ", err)
os.Exit(1)
}
fmt.Println("Success!")
os.Exit(0)
}