set_time_limit(0); ini_set('default_socket_timeout', 300); session_start(); /******************** INSTAGRAM API KEYS *****************************/ define("ClientId", '41f65a5c684048bca797dbf0775c9ec7'); define("ClientSECRET", '95647e6ef2a445ff92e8b27c82bf8da6'); //define("redirectURL", 'http://joinsocial.esy.es/index.php'); define("redirectURL", 'http://localhost/JSfaceLogin/Instagram/instagram.php'); require 'instagram/vendor/cosenary/instagram/src/Instagram.php'; use MetzWeb\Instagram\Instagram; $insta = new Instagram(array('apiKey' => '41f65a5c684048bca797dbf0775c9ec7', 'apiSecret' => '95647e6ef2a445ff92e8b27c82bf8da6', 'apiCallback' => 'http://localhost/JSfaceLogin/Instagram/instagram.php')); if (isset($_GET['code'])) { echo $_GET['code']; $accessToken = $insta->getOAuthToken($_GET['code']); $insta->setAccessToken($accessToken); $token = $insta->getAccessToken() . '<br>'; print_r($accessToken); $id = $accessToken->user->id; echo $full_name = $accessToken->user->username; echo '<pre>'; echo '</pre>'; $imagen = $accessToken->user->profile_picture; echo '<img src="' . $imagen . '"/>'; echo $insta->getUserLikes(1)->data[0]->likes->count . "Me gusta"; $follow = $insta->getUserFollows(); print_r($insta->getUserMedia()); } else { // check whether an error occurred if (isset($_GET['error'])) { echo 'An error occurred: ' . $_GET['error_description']; }
$code = $app->request->get('code'); $response = $client->post('https://api.instagram.com/oauth/access_token', array('body' => array('client_id' => CLIENT_ID, 'client_secret' => CLIENT_SECRET, 'grant_type' => 'authorization_code', 'redirect_uri' => REDIRECT_URL, 'code' => $code))); $data = $response->json(); } else { $login_url = "https://api.instagram.com/oauth/authorize?client_id={$client_id}&redirect_uri={$redirect_url}&scope=basic&response_type=code"; } $app->render('home.php', array('data' => $data, 'login_url' => $login_url)); }); $app->get('/login2', function () use($app, $instagram) { $login_url = $instagram->getLoginUrl(array('basic', 'likes')); if (!empty($_GET['code'])) { $code = $_GET['code']; $data = $instagram->getOAuthToken($code); //get access token using the authorization code $instagram->setAccessToken($data); $access_token = $instagram->getAccessToken(); //do anything you want with the access token } else { $app->render('login.php', array('login_url' => $login_url)); } }); $app->get('/user', function () use($app, $instagram, $user_id) { $results = $instagram->getUser($user_id); $app->render('user.php', array('user' => $results->data)); }); $app->get('/tags/search', function () use($app, $client, $access_token) { $tag = 'niagaraFalls'; $response = $client->get("https://api.instagram.com/v1/tags/{$tag}/media/recent?access_token={$access_token}"); $results = $response->json(); $app->render('images.php', array('results' => $results)); });