forked from masci/flickr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
60 lines (49 loc) · 1.46 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
package main
import (
"fmt"
"os"
"gopkg.in/masci/flickr.v2"
"gopkg.in/masci/flickr.v2/test"
)
func main() {
// retrieve Flickr credentials from env vars
apik := os.Getenv("FLICKRGO_API_KEY")
apisec := os.Getenv("FLICKRGO_API_SECRET")
// do not proceed if credentials were not provided
if apik == "" || apisec == "" {
fmt.Fprintln(os.Stderr, "Please set FLICKRGO_API_KEY and FLICKRGO_API_SECRET env vars")
os.Exit(1)
}
// create an API client with credentials
client := flickr.NewFlickrClient(apik, apisec)
// ask user to authorize this application
// first, get a request token
tok, err := flickr.GetRequestToken(client)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(2)
}
// build the authorizatin URL
url, err := flickr.GetAuthorizeUrl(client, tok)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(3)
}
// ask user to hit the authorization url with
// their browser, authorize this application and coming
// back with the confirmation token
var oauthVerifier string
fmt.Println("Open your browser at this url:", url)
fmt.Print("Then, insert the code:")
fmt.Scanln(&oauthVerifier)
// finally, get the access token
accessTok, err := flickr.GetAccessToken(client, tok, oauthVerifier)
fmt.Println("Successfully retrieved OAuth token", accessTok.OAuthToken, accessTok.OAuthTokenSecret)
// check everything works
resp, err := test.Login(client)
if err != nil {
fmt.Println(err)
} else {
fmt.Println(resp.Status, resp.User)
}
}