forked from huandu/facebook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
me_api.go
44 lines (35 loc) · 888 Bytes
/
me_api.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
package facebook
import (
"context"
)
type User struct {
ID string `json:"id"`
Email string `json:"email"`
}
type MeAPI interface {
AdAccounts(ctx context.Context, params Params) (Result, error)
Me(ctx context.Context, params Params) (Result, error)
User(ctx context.Context) (User, error)
}
func (c *Client) AdAccounts(ctx context.Context, params Params) (Result, error) {
return c.session.Get("/me/adaccounts", params)
}
func (c *Client) Me(ctx context.Context, params Params) (Result, error) {
res, err := c.session.Get("/me", params)
if err != nil {
return Result{}, err
}
return res, nil
}
func (c *Client) User(_ context.Context) (User, error) {
res, err := c.Me(context.Background(), FieldsParams("id", "email"))
if err != nil {
return User{}, err
}
var user User
err = res.Decode(&user)
if err != nil {
return User{}, err
}
return user, nil
}