-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathabout.go
120 lines (97 loc) · 3 KB
/
about.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package facebook
import (
jsonenc "encoding/json"
"errors"
"net/url"
"strings"
"github.com/tamboto2000/jsonextract/v3"
)
// about Section's collections
const (
aboutWorkAndEducation = "about_work_and_education"
aboutPlacesLived = "about_places"
aboutContactAndBasicInfo = "about_contact_and_basic_info"
aboutFamilyAndRelationships = "about_family_and_relationships"
aboutDetails = "about_details"
aboutLifeEvents = "about_life_events"
)
// About contains profile about section data
type About struct {
WorkHistory []Work `json:"workHistory,omitempty"`
EducationHistory []Education `json:"educationHistory,omitempty"`
PlacesLived []Place `json:"placesLived,omitempty"`
ContactAndBasicInfo *ContactAndBasicInfo `json:"contactAndBasicInfo,omitempty"`
FamilyAndRelationships *FamilyAndRelationships `json:"familyAndRelationships,omitempty"`
Details *Details `json:"details,omitempty"`
LifeEvents []LifeEvents `json:"lifeEvents,omitempty"`
profile *Profile
}
// SyncAbout fetch required tokens for requesting profile about data collections
func (prof *Profile) SyncAbout() error {
var handle string
if prof.Username != "" {
handle = prof.Username
} else {
handle = prof.ID
}
_, rawBody, err := prof.fb.getRequest("/"+handle+"/about", nil)
if err != nil {
return err
}
jsons, err := jsonextract.FromBytes(rawBody)
if err != nil {
return err
}
// find profile about section vars
if !findObj(jsons, func(json *jsonextract.JSON) bool {
obj := json.Object()
val, ok := obj["require"]
if !ok {
return false
}
if val.Kind() != jsonextract.Array {
return false
}
if findObj(val.Array(), func(json *jsonextract.JSON) bool {
obj := json.Object()
val, ok := obj["preloaderID"]
if !ok {
return false
}
if val.Kind() != jsonextract.String {
return false
}
if strings.Contains(val.String(), "adp_ProfileCometAboutAppSectionQueryRelayPreloader") {
if _, ok = obj["variables"]; ok {
if err := jsonenc.Unmarshal(json.Bytes(), prof.aboutSectionVars); err != nil {
return false
}
return true
}
}
return false
}) {
return true
}
return false
}) {
return errors.New("Important tokens for About section is not found")
}
prof.About = &About{profile: prof}
return nil
}
func (prof *Profile) reqAboutCollection(c string) ([]*jsonextract.JSON, error) {
coll := prof.aboutSectionVars.getColl(c)
vars := prof.aboutSectionVars.getVariables()
vars.CollectionToken = coll.ID
varsByts, _ := jsonenc.Marshal(vars)
reqBody := make(url.Values)
reqBody.Set("fb_api_req_friendly_name", "ProfileCometAboutAppSectionQuery")
reqBody.Set("variables", string(varsByts))
reqBody.Set("doc_id", prof.aboutSectionVars.QueryID)
_, rawBody, err := prof.fb.graphQlRequest(reqBody)
if err != nil {
return nil, err
}
return jsonextract.FromBytes(rawBody)
}