forked from ttacon/box
/
main.go
62 lines (52 loc) · 1.47 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
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
package main
import (
"flag"
"fmt"
"github.com/ttacon/box"
"github.com/ttacon/pretty"
"golang.org/x/oauth2"
)
var (
clientId = flag.String("cid", "", "OAuth Client ID")
clientSecret = flag.String("csec", "", "OAuth Client Secret")
accessToken = flag.String("atok", "", "Access Token")
refreshToken = flag.String("rtok", "", "Refresh Token")
fileName = flag.String("f", "", "file to upload new version of")
fileID = flag.String("fid", "", "id of the file we're updating")
)
func main() {
flag.Parse()
if len(*clientId) == 0 || len(*clientSecret) == 0 ||
len(*accessToken) == 0 || len(*refreshToken) == 0 ||
len(*fileName) == 0 {
fmt.Println("unfortunately all flags must be provided")
return
}
// Set our OAuth2 configuration up
var (
configSource = box.NewConfigSource(
&oauth2.Config{
ClientID: *clientId,
ClientSecret: *clientSecret,
Scopes: nil,
Endpoint: oauth2.Endpoint{
AuthURL: "https://app.box.com/api/oauth2/authorize",
TokenURL: "https://app.box.com/api/oauth2/token",
},
RedirectURL: "http://localhost:8080/handle",
},
)
tok = &oauth2.Token{
TokenType: "Bearer",
AccessToken: *accessToken,
RefreshToken: *refreshToken,
}
c = configSource.NewClient(tok)
)
resp, file, err := c.FileService().UploadFileVersion(*fileName, *fileID)
fmt.Println("resp: ", resp)
fmt.Println("err: ", err)
pretty.Print(file)
// Print out the new tokens for next time
fmt.Printf("\n%#v\n", tok)
}