exit; } } else { if (empty($_SESSION['expires_at']) || time() > $_SESSION['expires_at']) { // Token has expired, clear the state $_SESSION = array(); } if (empty($_SESSION['access_token'])) { // Start authorization process getAuthorizationCode(); } } require_once "../linkedin/connect.php"; $linkedin = new linkedin(API_KEY, API_SECRET, SCOPE); $linkedin->set($_SESSION['access_token'], $_SESSION['expires_in'], $_SESSION['expires_at'], $_SESSION['state']); $linkedin->save(); // Congratulations! You have a valid token. Now fetch your profile $user = fetch('GET', '/v1/people/~:(firstName,lastName)'); print "Hello {$user->firstName} {$user->lastName}."; print "<pre>"; print "Access token " . $_SESSION['access_token']; print "</pre>"; exit; function getAuthorizationCode() { $params = array('response_type' => 'code', 'client_id' => API_KEY, 'scope' => SCOPE, 'state' => uniqid('', true), 'redirect_uri' => REDIRECT_URI); // Authentication request $url = 'https://www.linkedin.com/uas/oauth2/authorization?' . http_build_query($params); // Needed to identify request when it returns to us $_SESSION['state'] = $params['state']; // Redirect user to authenticate