// Include the config file and the Podio library require_once 'config.php'; require_once '../PodioAPI.php'; // Setup the API client reference. Client ID and Client Secrets are defined // as constants in config.php Podio::setup(CLIENT_ID, CLIENT_SECRET); if (Podio::is_authenticated()) { // Use Podio::is_authenticated() to check is there's already an active session. // If there is you can make API calls right away. print "You were already authenticated and no authentication is needed. Close and reopen your browser to start over.<br>"; $status = PodioUserStatus::get(); print "Your user id is <b>{$status->user->id}</b> and you have <b>{$status->inbox_new}</b> unread messages in your inbox.<br><br>"; } elseif (!isset($_GET['code'])) { // If $_GET['code'] is not set it means we are not trying to authenticate. // In that case just display a link to start the serv flow $auth_url = htmlentities(Podio::authorize_url(REDIRECT_URI)); print "<a href='{$auth_url}'>Start authenticating</a>"; } else { // Otherwise try to authenticate using the code provided. // $_GET['error'] is set if there was a problem if (!isset($_GET['error'])) { Podio::authenticate('authorization_code', array('code' => $_GET['code'], 'redirect_uri' => REDIRECT_URI)); $access_token = Podio::$oauth->access_token; print "You have been authenticated. Wee!<br>"; print "Your access token is {$access_token}<br><br>"; print "Hang onto this access token along with the refresh token (store them in a session or similar) so you don't have to re-authenticate for every request.<br><br>"; // Now you can start making API calls. E.g. get your user status $status = PodioUserStatus::get(); print "Your user id is <b>{$status->user->id}</b> and you have <b>{$status->inbox_new}</b> unread messages in your inbox.<br><br>"; } else { print "There was a problem. The server said: {$_GET['error_description']}<br>";