-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtimeline.go
151 lines (144 loc) · 4.78 KB
/
timeline.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package gista
import (
"fmt"
"strings"
"time"
"github.com/aliforever/gista/constants"
"github.com/aliforever/gista/responses"
"github.com/aliforever/gista/utils"
)
type timeline struct {
ig *Instagram
}
func newTimeline(i *Instagram) *timeline {
return &timeline{ig: i}
}
func (t *timeline) GetUserFeed(userId int64, maxId *string) (res *responses.UserTimelineFeed, err error) {
res = &responses.UserTimelineFeed{}
req := t.ig.client.Request(fmt.Sprintf(constants.GetUserTimelineFeed, userId)).
AddParam("exclude_comment", "true").
AddParam("only_fetch_first_carousel_media", "false")
if maxId != nil {
req.AddParam("max_id", *maxId)
}
err = req.GetResponse(res)
return
}
func (t *timeline) GetTimelineFeed(maxId *string, options map[string]interface{}) (res *responses.TimelineFeed, err error) {
res = &responses.TimelineFeed{}
_, offset := time.Now().Zone()
asyncAds := t.ig.isExperimentEnabled("ig_android_ad_async_ads_universe", "is_enabled", false)
asyncAds2 := t.ig.isExperimentEnabled("ig_android_ad_async_ads_universe", "is_async_ads_in_headload_enabled", false)
asyncAds3 := t.ig.isExperimentEnabled("ig_android_ad_async_ads_universe", "is_double_request_enabled", false)
asyncAds4 := t.ig.isExperimentEnabled("ig_android_ad_async_ads_universe", "is_rti_enabled", false)
asyncAds5 := t.ig.isExperimentEnabled("ig_android_ad_async_ads_universe", "rti_delivery_backend", false)
asyncAdsStr := "0"
if asyncAds && asyncAds2 {
asyncAdsStr = "1"
}
asyncAdsStr2 := "0"
if asyncAds && asyncAds3 {
asyncAdsStr2 = "1"
}
asyncAdsStr3 := "0"
if asyncAds && asyncAds4 {
asyncAdsStr3 = "1"
}
asyncAdsStr4 := "0"
if asyncAds && asyncAds5 {
asyncAdsStr4 = "1"
}
request := t.ig.client.Request(constants.TimelineFeed).
SetSignedPost(false).
SetIsBodyCompressed(true).
AddHeader("X-Ads-Opt-Out", "0").
AddHeader("X-Google-AD-ID", t.ig.advertisingId).
AddHeader("X-DEVICE-ID", t.ig.uuid).
AddCSRFPost().
AddUuIdPost().
AddPost("is_prefetch", "0").
AddPhoneIdPost().
AddDeviceIdPost().
AddPost("client_session_id", t.ig.sessionId).
AddPost("battery_level", fmt.Sprintf("%d", utils.MtRand(25, 100))).
AddPost("is_charging", "0").
AddPost("will_sound_on", "1").
AddPost("is_on_screen", "true").
AddPost("timezone_offset", fmt.Sprintf("%d", offset)).
AddPost("is_async_ads_in_headload_enabled", asyncAdsStr).
AddPost("is_async_ads_double_request", asyncAdsStr2).
AddPost("is_async_ads_rti", asyncAdsStr3).
AddPost("rti_delivery_backend", asyncAdsStr4)
optionsHaveItem := func(item string) bool {
if options != nil {
if _, ok := options[item]; ok {
return true
}
}
return false
}
if optionsHaveItem("latest_story_pk") {
request.AddPost("latest_story_pk", options["latest_story_pk"].(string))
}
if maxId != nil {
request.AddPost("reason", "pagination")
request.AddPost("max_id", *maxId)
request.AddPost("is_pull_to_refresh", "0")
} else if optionsHaveItem("is_pull_to_refresh") && options["is_pull_to_refresh"] != "" {
request.AddPost("reason", "pull_to_refresh")
request.AddPost("is_pull_to_refresh", "1")
} else if optionsHaveItem("is_pull_to_refresh") {
request.AddPost("reason", "warm_start_fetch")
request.AddPost("is_pull_to_refresh", "0")
} else {
request.AddPost("reason", "cold_start_fetch")
request.AddPost("is_pull_to_refresh", "0")
}
if optionsHaveItem("seen_posts") {
switch options["seen_posts"].(type) {
case []string:
request.AddPost("seen_posts", strings.Join(options["seen_posts"].([]string), ","))
break
case string:
request.AddPost("seen_posts", options["seen_posts"].(string))
break
}
} else if maxId == nil {
request.AddPost("seen_posts", "")
}
if optionsHaveItem("unseen_posts") {
switch options["unseen_posts"].(type) {
case []string:
request.AddPost("unseen_posts", strings.Join(options["unseen_posts"].([]string), ","))
break
case string:
request.AddPost("unseen_posts", options["unseen_posts"].(string))
break
}
} else if maxId == nil {
request.AddPost("unseen_posts", "")
}
if optionsHaveItem("feed_view_info") {
switch options["feed_view_info"].(type) {
case []string:
request.AddPost("feed_view_info", strings.Join(options["feed_view_info"].([]string), ","))
break
case string:
request.AddPost("feed_view_info", options["feed_view_info"].(string))
break
}
} else if maxId == nil {
request.AddPost("feed_view_info", "")
}
if optionsHaveItem("push_disabled") && options["push_disabled"] != "" {
request.AddPost("push_disabled", "true")
}
if optionsHaveItem("recovered_from_crash") && options["recovered_from_crash"] != "" {
request.AddPost("recovered_from_crash", "true")
}
err = request.GetResponse(res)
return
}
func (t *timeline) UploadPhoto(photoFileName string, externalMetaData map[string]string) (res *responses.UserTimelineFeed, err error) {
return
}