-
Notifications
You must be signed in to change notification settings - Fork 0
/
callback.php
50 lines (43 loc) · 1.32 KB
/
callback.php
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
<?php
require_once('config.php');
if (isset($_REQUEST['code'])) {
$code = $_REQUEST['code'];
$url = "https://api.instagram.com/oauth/access_token";
$access_token_parameters = array(
'client_id' => CLIENT_ID,
'client_secret' => CLIENT_SECRET,
'grant_type' => 'authorization_code',
'redirect_uri' => REDIRECT_URI,
'code'=> $code
);
$curl = curl_init($url);
curl_setopt($curl,CURLOPT_POST,true);
curl_setopt($curl,CURLOPT_POSTFIELDS,$access_token_parameters);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);
$data = json_decode($result);
?>
<h1>Instagram Retriever Example</h1>
<h2>Parameters:</h2>
<pre>
<?php print_r($access_token_parameters); ?>
</pre>
<h2>Token response</h2>
<pre>
<?php print_r($data->access_token); ?>
</pre>
<?php
$url = "https://api.instagram.com/v1/users/".USER_ID."/media/recent/?access_token=".$data->access_token;
$response_json = file_get_contents($url);
$insta_response = json_decode($response_json);
?>
<h2>JSON encoded user data response</h2>
<pre>
<?php print_r($insta_response); ?>
</pre>
<?php
} else {
header('location:http://instagr.am/');
}
?>