-
Notifications
You must be signed in to change notification settings - Fork 56
/
contacts.go
87 lines (76 loc) · 2.08 KB
/
contacts.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
package goinsta
import (
"encoding/json"
)
type Contacts struct {
insta *Instagram
}
type Contact struct {
Numbers []string `json:"phone_numbers"`
Emails []string `json:"email_addresses"`
Name string `json:"first_name"`
}
type SyncAnswer struct {
Users []struct {
Pk int64 `json:"pk"`
Username string `json:"username"`
FullName string `json:"full_name"`
IsPrivate bool `json:"is_private"`
ProfilePicURL string `json:"profile_pic_url"`
ProfilePicID string `json:"profile_pic_id"`
IsVerified bool `json:"is_verified"`
HasAnonymousProfilePicture bool `json:"has_anonymous_profile_picture"`
ReelAutoArchive string `json:"reel_auto_archive"`
AddressbookName string `json:"addressbook_name"`
} `json:"users"`
Warning string `json:"warning"`
Status string `json:"status"`
}
func newContacts(insta *Instagram) *Contacts {
return &Contacts{insta: insta}
}
func (c *Contacts) SyncContacts(contacts *[]Contact) (*SyncAnswer, error) {
byteContacts, err := json.Marshal(contacts)
if err != nil {
return nil, err
}
syncContacts := &reqOptions{
Endpoint: `address_book/link/`,
IsPost: true,
Gzip: true,
Query: map[string]string{
"phone_id": c.insta.pid,
"module": "find_friends_contacts",
"source": "user_setting",
"device_id": c.insta.uuid,
"_uuid": c.insta.uuid,
"contacts": string(byteContacts),
},
}
body, _, err := c.insta.sendRequest(syncContacts)
if err != nil {
return nil, err
}
answ := &SyncAnswer{}
if err := json.Unmarshal(body, answ); err != nil {
return nil, err
}
return answ, nil
}
func (c *Contacts) UnlinkContacts() error {
unlinkBody := &reqOptions{
Endpoint: "address_book/unlink/",
IsPost: true,
Query: map[string]string{
"phone_id": c.insta.pid,
"device_id": c.insta.uuid,
"_uuid": c.insta.uuid,
"user_initiated": "true",
},
}
_, _, err := c.insta.sendRequest(unlinkBody)
if err != nil {
return err
}
return nil
}