PHP code example of datingvip / oauth2-client
1. Go to this page and download the library: Download datingvip/oauth2-client library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
datingvip / oauth2-client example snippets
$provider = new League\OAuth2\Client\Provider\<provider name>(array(
'clientId' => 'XXXXXXXX',
'clientSecret' => 'XXXXXXXX',
'redirectUri' => 'http://your-registered-redirect-uri/'
));
if ( ! isset($_GET['code'])) {
// If we don't have an authorization code then get one
$provider->authorize();
} else {
try {
// Try to get an access token (using the authorization code grant)
$t = $provider->getAccessToken('authorization_code', array('code' => $_GET['code']));
try {
// We got an access token, let's now get the user's details
$userDetails = $provider->getUserDetails($t);
foreach ($userDetails as $attribute => $value) {
var_dump($attribute, $value) . PHP_EOL . PHP_EOL;
}
} catch (Exception $e) {
// Failed to get user details
}
} catch (Exception $e) {
// Failed to get access token
}
}