-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathpost.go
63 lines (53 loc) · 1.34 KB
/
post.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
package instago
// This file decode JSON data returned by Instagram post API
import (
"encoding/json"
)
// Decode JSON data returned by Instagram post API
type postInfo struct {
GraphQL struct {
ShortcodeMedia IGMedia `json:"shortcode_media"`
} `json:"graphql"`
}
// Given the code of the post, return url of the post.
func CodeToUrl(code string) string {
return "https://www.instagram.com/p/" + code + "/"
}
// Given code of post, return information of the post with login status.
func (m *IGApiManager) GetPostInfo(code string) (em IGMedia, err error) {
url := CodeToUrl(code) + "?__a=1"
b, err := m.getHTTPResponse(url, "GET")
if err != nil {
return
}
// for development purpose
if saveRawJsonByte {
SaveRawJsonByte("post-"+code+"-with-login-", b)
}
pi := postInfo{}
err = json.Unmarshal(b, &pi)
if err != nil {
return
}
em = pi.GraphQL.ShortcodeMedia
return
}
// Given code of post, return information of the post without login status.
func GetPostInfoNoLogin(code string) (em IGMedia, err error) {
url := CodeToUrl(code) + "?__a=1"
b, err := GetHTTPResponseNoLogin(url, "GET")
if err != nil {
return
}
// for development purpose
if saveRawJsonByte {
SaveRawJsonByte("post-"+code+"-no-login-", b)
}
pi := postInfo{}
err = json.Unmarshal(b, &pi)
if err != nil {
return
}
em = pi.GraphQL.ShortcodeMedia
return
}