<?php
require 'vendor/autoload.php';
session_start();
$githubClientId = 'xxxxxxx';
$redirectUri = 'http://xx.xx.xx.xx/';
try {
if (isset($_GET['code'])) {
// GitHub'tan gelen code parametresini kullanarak token al
$token = $client->authenticate($githubClientId, $githubClientSecret, $_GET['code']);
// Token'ı sakla veya kullan
$_SESSION['github_token'] = $token;
// Kullanıcı bilgilerini al
$user = $client->api('current_user')->show();
// Kullanıcı bilgilerini kullan
echo 'Merhaba, ' . $user['login'];
} else {
// GitHub OAuth sayfasına yönlendir
$oauthUrl = 'https://github.com/login/oauth/authorize' . '?' . http_build_query([
'client_id' => $githubClientId,
'redirect_uri' => $redirectUri,
'scope' => 'user',
]);
header('Location: ' . $oauthUrl);
exit;
}
} catch (\Exception $e) {
// Hata durumunda hatayı ekrana yazdır
echo 'Hata: ' . $e->getMessage();
}
?>
acaba nerede hata yapmışım