<?php // Start a session and load the OAuth library. session_start(); require_once __DIR__ . '/oauth-client/src/yahoo.class.php'; // Create a new Yahoo object. $yahoo = new OAuthYahoo("0000000000000000", "0000000000000000000000000000000000000000", array("session_prefix" => "y_")); // Try to fetch an access token with the code in $_GET["code"]. Also check the state in $_GET["state"]. try { $yahoo->getAccessTokenFromCode("http://example.com/yahoo-1/code.php"); // -------- // If we got here, no error was thrown and an access token was successfully retrieved from the code. // Output the code and access token. echo "Success! Click the link at the bottom of the page to return home and fetch data using the access token.<br />\n"; echo "Code: " . htmlspecialchars($_GET["code"]) . "<br />\n"; echo "Access Token: " . htmlspecialchars($yahoo->accessToken()) . "\n<br /><br />\n\n"; } catch (Exception $error) { echo "Error - Click the link at the bottom of the page to return home and try again: " . $error->getMessage() . "\n<br /><br />\n\n"; } // Output a link to the homepage to fetch data using the access token. echo "<a href=\"./\">Home</a>\n";
<?php // Start a session and load the OAuth library. session_start(); require_once __DIR__ . '/oauth-client/src/yahoo.class.php'; // Delete the access token if needed. if (isset($_GET["del_token"]) && isset($_SESSION["y_token"])) { unset($_SESSION["y_token"]); } // Create a new Yahoo object. $yahoo = new OAuthYahoo("0000000000000000", "0000000000000000000000000000000000000000", array("session_prefix" => "y_")); // Output a Login Button. echo $yahoo->loginButton("Login with Yahoo!", "https://example.com/yahoo-1/code.php"); // If an access token exists (OAuth2::accessToken() does not return null), fetch the current user's data. if ($yahoo->accessToken() != null) { // The user is logged in, you can do whatever you like here. // In this example we just print the profile data, along with the profile picture and permissions. $profile = $yahoo->userProfile(); echo "<pre>" . print_r($profile, true) . "</pre><br /><br />\n\n"; } else { echo "You have not granted access to Yahoo. Click the link above.\n"; }