/** * Get an access token, either from the cookies or from instagram * TODO: Fallback if need to login again! */ private function getToken() { $access_token = $this->session->userdata('access_token'); if (!$access_token) { if (!isset($_GET['code'])) { show_error('You are not signed in. Please first sign in. (im.php-176). <a href="' . $this->config->item('base_url') . '">Home</a>'); } $this->load->library('rest'); $request = 'https://api.instagram.com/oauth/access_token'; $headers = array( 'client_id' => $this->config->item('config_id'), 'client-secret' => $this->config->item('client_secret'), 'code' => $_GET['code'], 'redirect_uri' => $this->config->item('redirect_uri'), ); $data = 'client_id=' . $this->config->item('client_id') . '&client_secret=' . $this->config->item('client_secret') . '&code=' . $_GET['code'] . '&redirect_uri=' . $this->config->item('redirect_uri') . '&grant_type=authorization_code'; $result = Rest::http_request($request, $headers, 'POST', $data); if ($result->code != 200) { show_error($result->error . ' (im.php 190)'); } $result = json_decode($result->data); $access_token = $result->access_token; } $this->session->set_userdata(array('access_token' => $access_token)); return $access_token; }