public function connect($code) { $privateInstagram = new InstagramAPI(array('apiKey' => $this->getApiKey(), 'apiSecret' => $this->getApiSecret(), 'apiCallback' => $this->getApiCallback())); $oAuthToken = $privateInstagram->getOAuthToken($code[0]); $privateInstagram->setAccessToken($oAuthToken); return [$code[0], $privateInstagram]; }
* Instagram PHP API * * @link https://github.com/cosenary/Instagram-PHP-API * @author Christian Metz * @since 01.10.2013 */ require '../src/Instagram.php'; use MetzWeb\Instagram\Instagram; // initialize class $instagram = new Instagram(array('apiKey' => 'YOUR_APP_KEY', 'apiSecret' => 'YOUR_APP_SECRET', 'apiCallback' => 'YOUR_APP_CALLBACK')); // receive OAuth code parameter $code = $_GET['code']; // check whether the user has granted access if (isset($code)) { // receive OAuth token object $data = $instagram->getOAuthToken($code); $username = $username = $data->user->username; // store user access token $instagram->setAccessToken($data); // now you have access to all authenticated user methods $result = $instagram->getUserMedia(); } else { // check whether an error occurred if (isset($_GET['error'])) { echo 'An error occurred: ' . $_GET['error_description']; } } ?> <!DOCTYPE html> <html lang="en"> <head>
<?php 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'])) {
<?php /***************************************** * Saves user access toekn to database /****************************************/ require HIPSTR_DIR . '/classes/Instagram.php'; use MetzWeb\Instagram\Instagram; // Get options $options = get_option('hipstr_options'); if (!empty($options['client_id']) && !empty($options['client_secret'])) { // Initialize class $instagram = new Instagram(array('apiKey' => $options['client_id'], 'apiSecret' => $options['client_secret'], 'apiCallback' => WEBSITE_URL)); // Check whether the user has granted access if (isset($_GET['code'])) { // Receive OAuth token object $data = $instagram->getOAuthToken($_GET['code']); // Save user access token to database $options['token'] = $data; update_option('hipstr_options', $options); } }
/** * @param $request * * @return mixed */ protected function _getAccessToken($request) { return $this->_instagram->getOAuthToken($request->query['code']); }