-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoken.go
33 lines (28 loc) · 800 Bytes
/
token.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
package twitter
import (
"encoding/json"
"errors"
"net/http"
)
func fetchToken() (string, error) {
h := http.Header{}
// h.Set("accept", "application/json,text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8")
// h.Set("accept-encoding", "gzip")
// h.Set("accept-language", "en-US,en;q=0.5")
// h.Set("connection", "keep-alive")
h.Set("authorization", auth)
req, _ := http.NewRequest("POST", activate, nil)
req.Header = h
resp, err := http.DefaultClient.Do(req)
if err != nil {
return "", errors.New("Error doing request: " + err.Error())
}
var v struct {
GuestToken string `json:"guest_token"`
}
err = json.NewDecoder(resp.Body).Decode(&v)
if err != nil {
return "", errors.New("Error decoding json: " + err.Error())
}
return v.GuestToken, nil
}