GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — cloudwatcher/examples/dropbox/dropbox.go at main · Matrix86/cloudwatcher

Expand file tree

/

dropbox.go

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
87 lines (75 loc) · 1.6 KB
/

dropbox.go

Copy path

File metadata and controls

87 lines (75 loc) · 1.6 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"context"
"encoding/json"
"fmt"
"github.com/Matrix86/cloudwatcher"
"github.com/dropbox/dropbox-sdk-go-unofficial/dropbox"
"golang.org/x/oauth2"
"time"
)
const (
ClientId = ""
ClientSecret = ""
Token = ""
)
func getAuthCode() (string, error) {
conf := &oauth2.Config{
ClientID: ClientId,
ClientSecret: ClientSecret,
Endpoint: dropbox.OAuthEndpoint(""),
}
fmt.Printf("1. Go to %v\n", conf.AuthCodeURL("state"))
fmt.Printf("2. Click \"Allow\" (you might have to log in first).\n")
fmt.Printf("3. Copy the authorization code.\n")
fmt.Printf("Enter the authorization code here: ")
var code string
if _, err := fmt.Scan(&code); err != nil {
return "", err
}
ctx := context.Background()
token, err := conf.Exchange(ctx, code)
if err != nil {
return "", err
}
b, err := json.Marshal(token)
if err != nil {
return "", err
}
return string(b), nil
}
func main() {
s, err := cloudwatcher.New("dropbox", "", 2*time.Second)
if err != nil {
fmt.Printf("ERROR: %s", err)
return
}
config := map[string]string{
"debug": "true",
"token": Token,
}
if v, ok := config["token"]; !ok || v == "" {
token, err := getAuthCode()
if err != nil {
fmt.Printf("ERROR: %s", err)
return
}
fmt.Printf("NEW TOKEN: %s\n", token)
config["token"] = token
}
err = s.SetConfig(config)
if err != nil {
fmt.Printf("ERROR: %s", err)
return
}
err = s.Start()
defer s.Close()
for {
select {
case v := <-s.GetEvents():
fmt.Printf("EVENT: %s %s\n", v.Key, v.TypeString())
case e := <-s.GetErrors():
fmt.Printf("ERROR: %s\n", e)
}
}
}
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.