-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathusers.go
41 lines (37 loc) · 1.01 KB
/
users.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
package fbmsgr
import (
"encoding/json"
"errors"
"net/url"
"github.com/unixpickle/essentials"
)
// ProfilePicture gets a URL to a user's profile picture.
func (s *Session) ProfilePicture(fbid string) (picURL *url.URL, err error) {
defer essentials.AddCtxTo("fbmsgr: get profile picture", &err)
params, err := s.commonParams()
if err != nil {
return nil, err
}
params.Set("requests[0][fbid]", fbid)
params.Set("requests[0][type]", "profile_picture")
params.Set("requests[0][width]", "50")
params.Set("requests[0][height]", "50")
params.Set("requests[0][resize_mode]", "p")
reqURL := BaseURL + "/ajax/image_source.php?dpr=1"
resp, err := s.jsonForPost(reqURL, params)
if err != nil {
return nil, err
}
var respObj struct {
Payload []struct {
URI string `json:"uri"`
} `json:"payload"`
}
if err := json.Unmarshal(resp, &respObj); err != nil {
return nil, err
}
if len(respObj.Payload) != 1 {
return nil, errors.New("unexpected number of results")
}
return url.Parse(respObj.Payload[0].URI)
}