Created
February 20, 2016 19:49
-
-
Save mymizan/1bb595b0ac4dc444d1c8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
session_start(); | |
require_once __DIR__ . "/vendor/autoload.php"; | |
require_once __DIR__ . "/config.php"; | |
//retrieve images | |
if (!empty($_SESSION['data'])){ | |
$token = $_SESSION['data']['access_token']; | |
$client = new GuzzleHttp\Client(); | |
$response = $client->request('GET', 'https://api.instagram.com/v1/users/self/media/recent/', array( | |
'query' => array( | |
'access_token' => $token, | |
'COUNT' => 99999999999, | |
'client_id' => CLIENT_ID, | |
))); | |
$body = (string) $response->getBody(); | |
echo $body; | |
die; | |
} | |
//check Oauth flow | |
if (empty($_REQUEST['code']) ) { | |
$oauth_url = "https://api.instagram.com/oauth/authorize/?client_id=" . CLIENT_ID . "&redirect_uri=" . APPROOT . "/oauth.php&response_type=code"; | |
header('Location: ' . $oauth_url); | |
//&scope=likes+comments+public_content+follower_list+relationships | |
die; | |
} else { | |
//request access token | |
$client = new GuzzleHttp\Client(); | |
$response = $client->request('POST', 'https://api.instagram.com/oauth/access_token', array( | |
'form_params' => array( | |
'code' => $_REQUEST['code'], | |
'client_secret' => CLIENT_SECRET, | |
'client_id' => CLIENT_ID, | |
'grant_type' => 'authorization_code', | |
'redirect_uri' => APPROOT . "/oauth.php", | |
))); | |
if ($response->getStatusCode() == 200){ | |
$body = $response->getBody(); | |
$data = json_decode($body->getContents(), true); | |
//save access token | |
$_SESSION['data'] = $data; | |
echo $data['access_token']; | |
} else { | |
echo $response->getReasonPhrase(); | |
echo (string) $response->getBody(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment