-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex - Copy.php
More file actions
221 lines (163 loc) · 6.19 KB
/
index - Copy.php
File metadata and controls
221 lines (163 loc) · 6.19 KB
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>InstaFeed.me - Search Instagram profiles</title>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
</head>
<body>
<div class="page-header">
<h1>InstaFeed.me - Search Instagram profiles</h1>
<?php
/*Get instagram uid of a user*/
function getUID($username){
$username = strtolower($username); // sanitization
$access_token = "309165108.d64dad5.0bd360f0dab34b1f9c0e00357ef4d90e";
$json_link = "https://api.instagram.com/v1/users/search?q=".$username."&access_token=".$access_token;
$get = file_get_contents($json_link);
$obj = json_decode($get);
foreach($obj->data as $user){
if($user->username == $username){
return $user->id;
}
}
return '00000000'; // return this if nothing is found
}
//$uid = getUID('pewdiepie');
//echo "<h1>UID: ".$uid."</h1>";
/*Query to get user data*/
function makeQuery($uid, $photo_count){
$uid=$uid;
// instruction to get your access token here https://www.codeofaninja.com/2015/05/get-instagram-access-token.html
$access_token="309165108.d64dad5.0bd360f0dab34b1f9c0e00357ef4d90e";
$photo_count=$photo_count;
$json_link="https://api.instagram.com/v1/users/{$uid}/media/recent/?";
$json_link.="access_token={$access_token}&count={$photo_count}";
$get = file_get_contents($json_link);
$obj = json_decode($get, true, 512);
return $obj;
}
function searchUser(){
$username = $_POST['username'];
$photo_count = $_POST['photo_count'];
$uid = getUID($username);
$obj = makeQuery($uid, $photo_count);
/*Display user profile data (pics, comments etc.)*/
for($i=0; $i<$length; $i++){
$created = $obj['data'][$i]['comments']['data'][0]['created_time'];
$text = $obj['data'][$i]['comments']['data'][0]['text'];
$user = $obj['data'][$i]['comments']['data'][0]['from']['username'];
$pic = $obj['data'][$i]['comments']['data'][0]['from']['profile_picture'];
echo "<img src='".$pic."' alt='".$user."' height='42' width='42'>";
echo "<p><b>".$user."</b> says: ".$text."</p>";
}
}
$photo_count = 12;
$obj = makeQuery($photo_count);
/*Print json obj data as an array*/
echo "<pre>";
print_r($obj);
echo "</pre>";
//$length = count($obj['data']);
//echo "<p>Total queries: ".$length."</p>";
/*Display user profile data (pics, comments etc.)*/
/*for($i=0; $i<$length; $i++){
$created = $obj['data'][$i]['comments']['data'][0]['created_time'];
$text = $obj['data'][$i]['comments']['data'][0]['text'];
$user = $obj['data'][$i]['comments']['data'][0]['from']['username'];
$pic = $obj['data'][$i]['comments']['data'][0]['from']['profile_picture'];
echo "<img src='".$pic."' alt='".$user."' height='42' width='42'>";
echo "<p><b>".$user."</b> says: ".$text."</p>";
//echo $obj['data'][0]['comments']['count'];
}*/
if(isset($_POST['submit'])){
$username = $_POST['username'];
$photo_count = $_POST['photo_count'];
$uid = getUID($username);
if($uid){
$obj = makeQuery($uid, $photo_count);
}
/*Display user profile data (pics, comments etc.)*/
for($i=0; $i<$length; $i++){
$created = $obj['data'][$i]['comments']['data'][0]['created_time'];
$text = $obj['data'][$i]['comments']['data'][0]['text'];
$user = $obj['data'][$i]['comments']['data'][0]['from']['username'];
$pic = $obj['data'][$i]['comments']['data'][0]['from']['profile_picture'];
echo "<img src='".$pic."' alt='".$user."' height='42' width='42'>";
echo "<p><b>".$user."</b> says: ".$text."</p>";
}
}
echo "<form method='post' action='search.php'>";
echo "<br>";
echo "Search user<br>";
echo "<input type='text' name='username' placeholder='Enter username...'>";
echo "Pictures to show (number)<br>";
echo "<input type='text' name='photo_count' placeholder='Enter photo count...'>";
echo "<br><br>";
echo "<input type='submit' name='submit' value='Search'>";
echo "</form>";
/*foreach($obj["data"] as $data){
echo "<b>".$data."</b>";
foreach($data as $value){
$i++;
$comments = $data["type"];
echo "<p>Type:".$i." ".$comments."</p>";
//echo "<p>".$data." => ".$value."</p>";
}
}*/
/*foreach($obj["data"] as $data => $value){
echo "<h3>".$data.". ".$value."</h3>";
foreach($value as $info => $inside){
echo "<p>".$info." => ".$inside."</p>";
}
}*/
/*foreach($obj["data"] as $data){
echo "<p>".$data."</p>";
foreach($data as $info){
echo "<p>Info: ".$info."</p>";
foreach($info as $comments){
echo "<p>comments: ".$comments["location"]."</p>";
}
}
}*/
/*
foreach ($obj as $data => $comments) {
echo "<p>".$data."</p>";
foreach ($comments as $array => $text) {
echo "<p>".$array." => ".$text."</p>";
foreach ($text as $key => $value) {
echo "<p>".$key." => ".$value."</p>";
}
}
}
*/
/*foreach($obj['pagination'] as $item) {
print $item['next_url'];
}*/
?>
</div>
<div class="container">
<!-- <form method='post' action="<?php $_PHP_SELF ?>">
<br>
Search user<br>
<input type='text' name='username' placeholder='Enter username...'>
Pictures to show (number)<br>
<input type='text' name='photo_count' placeholder='Enter photo count...'>
<br><br>
<input type='submit' name='submit' value='Search'>
</form>
-->
<div class="col-lg-12">
<!-- Instagram feed will be here -->
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</body>
</html>