-
Notifications
You must be signed in to change notification settings - Fork 13
/
facebook.go
55 lines (45 loc) · 1.06 KB
/
facebook.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
package social
import (
"context"
"encoding/json"
"io"
"net/http"
"net/url"
)
type facebookUserData struct {
ID string `json:"id"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
Avatar string `json:"avatar"`
Email string `json:"email"`
}
type Facebook struct {
}
func (p *Facebook) GetUserData(_ context.Context, token string, _ bool) (*UserData, error) {
resp, err := http.Get("https://graph.facebook.com/me?access_token=" +
url.QueryEscape(token))
defer func(body io.ReadCloser) {
_ = body.Close()
}(resp.Body)
if err != nil {
return nil, err
}
// read all response body
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
facebookUser := &facebookUserData{}
err = json.Unmarshal(body, facebookUser)
if err != nil {
panic(err.Error())
}
return &UserData{
ID: facebookUser.ID,
FirstName: facebookUser.FirstName,
LastName: facebookUser.LastName,
Avatar: facebookUser.Avatar,
Email: facebookUser.Email,
}, nil
}
func (p *Facebook) SetIsAndroid(_ bool) {}