-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
47 lines (42 loc) · 1.18 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
package main
import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"log"
plurgo "github.com/clsung/plurgo/plurkgo"
)
var credPath = flag.String("config", "config.json", "Path to configuration file containing the application's credentials.")
func main() {
flag.Parse()
plurkOAuth, err := plurgo.ReadCredentials(*credPath)
if err != nil {
log.Fatalf("Error reading credential, %v", err)
}
accessToken, authorized, err := plurgo.GetAccessToken(plurkOAuth)
if authorized {
bytes, err := json.MarshalIndent(plurkOAuth, "", " ")
if err != nil {
log.Fatalf("failed to store credential: %v", err)
}
err = ioutil.WriteFile(*credPath, bytes, 0700)
if err != nil {
log.Fatal("failed to write credential: %v", err)
}
}
result, err := plurgo.CallAPI(accessToken, "/APP/Profile/getOwnProfile", map[string]string{})
if err != nil {
log.Fatalf("failed: %v", err)
}
fmt.Println(string(result))
var data = map[string]string{}
data["content"] = "Test plurkAdd from plurkgo"
data["qualifier"] = "shares"
data["lang"] = "ja"
result, err = plurgo.CallAPI(accessToken, "/APP/Timeline/plurkAdd", data)
if err != nil {
log.Fatalf("failed: %v", err)
}
fmt.Println(string(result))
}