-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
46 lines (37 loc) · 927 Bytes
/
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
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"github.com/stacktic/dropbox"
)
type config struct {
Clientid string `json:"clientid"`
Clientsecret string `json:"clientsecret"`
Token string `json:"token"`
Destination string `json:"destination"`
DropboxPath string `json:"dropboxpath"`
}
func main() {
configFile, err := ioutil.ReadFile("config.json")
if err != nil {
panic("Error opening config file: " + err.Error())
}
var c config
err = json.Unmarshal(configFile, &c)
if err != nil {
panic(err)
}
var db *dropbox.Dropbox
// 1. Create a new dropbox object.
db = dropbox.NewDropbox()
// 2. Provide your clientid and clientsecret (see prerequisite).
db.SetAppInfo(c.Clientid, c.Clientsecret)
// 3. Provide the user token.
db.SetAccessToken(c.Token)
fmt.Println(c.DropboxPath)
err = db.DownloadToFile(c.DropboxPath, c.Destination, "")
if err != nil {
panic(err)
}
}