-
Notifications
You must be signed in to change notification settings - Fork 3
/
friends.go
128 lines (104 loc) · 3.1 KB
/
friends.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
121
122
123
124
125
126
127
128
package facebook
const (
sectionFriends = "FRIENDS"
friendsAll = "friends_all"
)
// Friends contains retrieved friend list and method for pagination
type Friends struct {
}
// // SyncFriends retrieve importants tokens to retrieve friend list
// func (prof *Profile) SyncFriends() error {
// _, rawBody, err := prof.fb.getRequest("/"+prof.ID+"/friends", nil)
// if err != nil {
// return err
// }
// jsons, err := jsonextract.FromBytes(rawBody)
// if err != nil {
// return err
// }
// // find friends tokens
// if !findObj(jsons, func(json *jsonextract.JSON) bool {
// if val, ok := json.Object()["require"]; ok {
// if findObj(val.Array(), func(json *jsonextract.JSON) bool {
// if val, ok := json.Object()["variables"]; ok {
// if _, ok := val.Object()["sectionToken"]; ok {
// prof.friendSectionVars = json
// return true
// }
// }
// return false
// }) {
// return true
// }
// }
// return false
// }) {
// return errors.New("Important tokens for Friends section is not found")
// }
// return nil
// }
// // AllFriends prepare for paging all friends list
// func (prof *Profile) AllFriends() (*Friends, error) {
// _, rawBody, err := prof.fb.getRequest("/"+prof.ID+"/friends_all", nil)
// if err != nil {
// return nil, err
// }
// jsons, err := jsonextract.FromBytes(rawBody)
// if err != nil {
// return nil, err
// }
// friends := new(Friends)
// jsons, err = prof.reqFriends(friendsAll, "")
// if err != nil {
// return nil, err
// }
// findKeyObj(jsons, "pageItems", func(parent, obj *jsonextract.JSON) bool {
// return true
// })
// return friends, nil
// }
// func (prof *Profile) reqFriends(c, cursor string) ([]*jsonextract.JSON, error) {
// var section *jsonextract.JSON
// for _, val := range prof.profileSections.Object()["edges"].Array() {
// node, ok := val.Object()["node"]
// if !ok {
// continue
// }
// if val, ok := node.Object()["section_type"]; ok && val.String() == sectionFriends {
// section = node
// break
// }
// }
// if section == nil {
// return nil, errors.New("Important tokens for Friends section is not found")
// }
// var coll *jsonextract.JSON
// for _, val := range section.Object()["all_collections"].Object()["nodes"].Array() {
// tabKey, ok := val.Object()["tab_key"]
// if !ok {
// continue
// }
// if tabKey.String() == c {
// coll = val
// break
// }
// }
// vars := prof.friendSectionVars.Object()["variables"]
// vars.Object()["collectionToken"].SetStr(coll.Object()["id"].String())
// var apiName string
// if cursor == "" {
// apiName = "ProfileCometTopAppSectionQuery"
// } else {
// apiName = "ProfileCometAppCollectionListRendererPaginationQuery"
// // alter the variables
// }
// reqBody := make(url.Values)
// reqBody.Set("fb_api_req_friendly_name", apiName)
// reqBody.Set("variables", string(vars.Bytes()))
// reqBody.Set("doc_id", prof.friendSectionVars.Object()["queryID"].String())
// _, rawBody, err := prof.fb.graphQlRequest(reqBody)
// if err != nil {
// return nil, err
// }
// return jsonextract.FromBytes(rawBody)
// }