Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require __DIR__ . '/vendor/autoload.php';
- session_start();
- echo ('Main screen turn on!<br/><br/>');
- $provider = new \Wohali\OAuth2\Client\Provider\Discord([
- 'clientId' => 'xxxx',
- 'clientSecret' => 'xxxx',
- 'redirectUri' => 'xxx'
- ]);
- if (!isset($_GET['code'])) {
- // Step 1. Get authorization code
- $authUrl = $provider->getAuthorizationUrl();
- $_SESSION['oauth2state'] = $provider->getState();
- header('Location: ' . $authUrl);
- // Check given state against previously stored one to mitigate CSRF attack
- } elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) {
- unset($_SESSION['oauth2state']);
- exit('Invalid state');
- } else {
- // Step 2. Get an access token using the provided authorization code
- $token = $provider->getAccessToken('authorization_code', [
- 'code' => $_GET['code']
- ]);
- // Show some token details
- echo '<h2>Token details:</h2>';
- echo 'Token: ' . $token->getToken() . "<br/>";
- echo 'Refresh token: ' . $token->getRefreshToken() . "<br/>";
- echo 'Expires: ' . $token->getExpires() . " - ";
- echo ($token->hasExpired() ? 'expired' : 'not expired') . "<br/>";
- // Step 3. (Optional) Look up the user's profile with the provided token
- try {
- $user = $provider->getResourceOwner($token);
- // echo '<h2>Resource owner details:</h2>';
- // printf('Hello %s#%s!<br/><br/>', $user->getUsername(), $user->getDiscriminator());
- $dados = $user->toArray();
- echo '<br>seu id é: ' . $dados['id'];
- } catch (Exception $e) {
- // Failed to get user details
- exit('Oh dear...');
- }
- }
- // create $provider as in the initial example
- $existingAccessToken = getAccessTokenFromYourDataStore();
- if ($existingAccessToken->hasExpired()) {
- $newAccessToken = $provider->getAccessToken('refresh_token', [
- 'refresh_token' => $existingAccessToken->getRefreshToken()
- ]);
- // Purge old access token and store new access token to your data store.
- }
- // create $provider as in the initial example
- try {
- // Try to get an access token using the client credentials grant.
- $accessToken = $provider->getAccessToken('client_credentials');
- } catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e) {
- // Failed to get the access token
- exit($e->getMessage());
- }
- //conexão sql
- $servername = 'lxx';
- $username = 'xxt';
- $password = 'xxxx';
- $database = 'mxxx';
- //conectando
- $conn = mysqli_connect($servername, $username, $password);
- //checando conexão
- if (!$conn) {
- die('Falha na conexão: ' . mysqli_connect_error());
- }
- echo 'Conectado com sucesso! <br>';
- // seleciona a base de dados em que vamos trabalhar
- mysqli_select_db($conn, $database);
- // cria a instrução SQL que vai selecionar os dados
- $query = sprintf('SELECT id FROM getdiscord');
- // executa a query
- $dados = mysqli_query($conn, $query) or die(mysqli_error($conn));
- // transforma os dados em um array
- $linha = mysqli_fetch_assoc($dados);
- // calcula quantos dados retornaram
- $total = mysqli_num_rows($dados);
- mysqli_close($conn);
- echo 'Resultado: ';
- var_dump($linha);
- echo '<br>Total: ' . $total;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement