-
Notifications
You must be signed in to change notification settings - Fork 0
/
somethng.go
123 lines (111 loc) · 3.13 KB
/
somethng.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
package main
import (
"encoding/json"
"fmt"
"html/template"
"io/ioutil"
"net/http"
"os"
)
type autoGenerated struct {
Pagination struct {
NextMinID string `json:"next_min_id"`
MinTagID string `json:"min_tag_id"`
DeprecationWarning string `json:"deprecation_warning"`
} `json:"pagination"`
Data []struct {
ID string `json:"id"`
User struct {
ID string `json:"id"`
FullName string `json:"full_name"`
ProfilePicture string `json:"profile_picture"`
Username string `json:"username"`
} `json:"user"`
Images struct {
Thumbnail struct {
Width int `json:"width"`
Height int `json:"height"`
URL string `json:"url"`
} `json:"thumbnail"`
LowResolution struct {
Width int `json:"width"`
Height int `json:"height"`
URL string `json:"url"`
} `json:"low_resolution"`
StandardResolution struct {
Width int `json:"width"`
Height int `json:"height"`
URL string `json:"url"`
} `json:"standard_resolution"`
} `json:"images"`
CreatedTime string `json:"created_time"`
Caption struct {
ID string `json:"id"`
Text string `json:"text"`
CreatedTime string `json:"created_time"`
From struct {
ID string `json:"id"`
FullName string `json:"full_name"`
ProfilePicture string `json:"profile_picture"`
Username string `json:"username"`
} `json:"from"`
} `json:"caption"`
UserHasLiked bool `json:"user_has_liked"`
Likes struct {
Count int `json:"count"`
} `json:"likes"`
Tags []string `json:"tags"`
Filter string `json:"filter"`
Comments struct {
Count int `json:"count"`
} `json:"comments"`
Type string `json:"type"`
Link string `json:"link"`
Location interface{} `json:"location"`
Attribution interface{} `json:"attribution"`
UsersInPhoto []interface{} `json:"users_in_photo"`
} `json:"data"`
Meta struct {
Code int `json:"code"`
} `json:"meta"`
}
type pageData struct {
PageTitle string
Listy []string
}
var tmpl *template.Template
var token = "" ///Insert your token here
var hashtag = "yang"
func main() {
tmpl = template.Must(template.ParseFiles("layout.html"))
http.HandleFunc("/", indexhandler)
http.ListenAndServe(":8080", nil)
}
func indexhandler(w http.ResponseWriter, r *http.Request) {
fmt.Println("donno why ")
//get jason data from instagram api
sdata := ""
response, err := http.Get("https://api.instagram.com/v1/tags/yang/media/recent?access_token=332074502.e1e82ec.36570dc7e00f461687dcb73aa88d4fc3")
if err != nil {
fmt.Printf("request failed: %s", err)
defer fmt.Println("!")
os.Exit(1)
}
data, _ := ioutil.ReadAll(response.Body)
sdata = string(data)
//fmt.Println(sdata)
var result autoGenerated
json.Unmarshal([]byte(sdata), &result)
var listofimages []string
for _, rezdata := range result.Data {
p := rezdata.Images.LowResolution.URL
listofimages = append(listofimages, p)
fmt.Println(listofimages)
}
dt := pageData{
PageTitle: "My insta list",
Listy: listofimages,
}
fmt.Println("executing ")
tmpl.Execute(w, dt)
}