• 24-01-2024, 20:19:06
    #1
    Merhaba, bir projem için PHP kullanarak github ile giriş yap seçeneği kullanmak istiyorum. projede böyle bir hata aldım ne yapabilirim ?
    şöyle bir hata alıyorum. Hata: Undefined method called: "getAuthorizationUrl"
    <?php
    require 'vendor/autoload.php';
    
    use Github\Client;
    
    session_start();
    
    $githubClientId = 'xxxxxxx';
    $githubClientSecret = 'xxxxxx';
    $redirectUri = 'http://xx.xx.xx.xx/';
    
    $client = new Client();
    
    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 = $client->getAuthorizationUrl($githubClientId, $redirectUri, ['user']);
            header('Location: ' . $oauthUrl);
            exit;
        }
    } catch (\Exception $e) {
        // Hata durumunda hatayı ekrana yazdır
        echo 'Hata: ' . $e->getMessage();
    }
    ?>
  • 24-01-2024, 20:26:15
    #2
    <?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();
    }
    ?>
    • yusufcagaloglu
    yusufcagaloglu bunu beğendi.
    1 kişi bunu beğendi.
  • 24-01-2024, 20:35:20
    #3
    Misafir adlı üyeden alıntı: mesajı görüntüle
    <?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
  • 24-01-2024, 20:35:52
    #4
    yusufcagaloglu adlı üyeden alıntı: mesajı görüntüle
    acaba nerede hata yapmışım
    oldu mu
    • yusufcagaloglu
    yusufcagaloglu bunu beğendi.
    1 kişi bunu beğendi.
  • 24-01-2024, 20:38:54
    #5
    Misafir adlı üyeden alıntı: mesajı görüntüle
    oldu mu
    evet düzeldi peki isim eposta foto gibi değerleri çekip veritabanına nasıl kaydedebiliriz.
    bir de sessiona kaydediyor.
  • 24-01-2024, 20:43:05
    #6
    $userInfo = $client->api('current_user')->show();
    $githubUsername = $userInfo['login'];
    $githubEmail = $userInfo['email'];
    $githubAvatarUrl = $userInfo['avatar_url'];
  • 24-01-2024, 20:44:00
    #7
    $servername = "localhost";
    $username = "kullanici_adi";
    $password = "sifre";
    $dbname = "veritabani_adi";
    
    $conn = new mysqli($servername, $username, $password, $dbname);
    
    
    if ($conn->connect_error) {
        die("Bağlantı hatası: " . $conn->connect_error);
    }
    
    $sql = "INSERT INTO kullanici_tablosu (github_username, github_email, avatar_url) VALUES ('$githubUsername', '$githubEmail', '$githubAvatarUrl')";
    
    if ($conn->query($sql) === TRUE) {
        echo "Kullanıcı bilgileri başarıyla veritabanına eklendi";
    } else {
        echo "Hata: " . $sql . "<br>" . $conn->error;
    }
    
    $conn->close();
  • 25-01-2024, 03:14:12
    #8
    Misafir adlı üyeden alıntı: mesajı görüntüle
    $userInfo = $client->api('current_user')->show();
    $githubUsername = $userInfo['login'];
    $githubEmail = $userInfo['email'];
    $githubAvatarUrl = $userInfo['avatar_url'];
    Bunu githublogin.php sayfasına header ile yönlendirme yapmadan öncesine yazdığımda hata veriyor nasıl yapılmalı acaba? Bunları yazıp ardınsan veritabanına kaydetme işlemi yapıyorum acaba orası mı yanlış oluyor. O zaman tüm değerleri session olarak kaydedeyim ana sayfadan session ları dinleyip veritabanına kaydederim diyorum. Acaba olur mu
  • 25-01-2024, 03:29:55
    #9
    yusufcagaloglu adlı üyeden alıntı: mesajı görüntüle
    Bunu githublogin.php sayfasına header ile yönlendirme yapmadan öncesine yazdığımda hata veriyor nasıl yapılmalı acaba? Bunları yazıp ardınsan veritabanına kaydetme işlemi yapıyorum acaba orası mı yanlış oluyor. O zaman tüm değerleri session olarak kaydedeyim ana sayfadan session ları dinleyip veritabanına kaydederim diyorum. Acaba olur mu
    <?php
    require 'vendor/autoload.php';
     
    use Github\Client;
     
    session_start();
     
    $githubClientId = 'xxxxxxx';
    $githubClientSecret = 'xxxxxx';
    $redirectUri = 'http://xx.xx.xx.xx/githublogin.php';
    
    $client = new Client();
     
    try {
        if (isset($_GET['code'])) {
            // GitHub'tan gelen code parametresini kullanarak token al
            $token = $client->authenticate($githubClientId, $githubClientSecret, $_GET['code']);
    
            // Kullanıcı bilgilerini al
            $userInfo = $client->api('current_user')->show();
            $githubUsername = $userInfo['login'];
            $githubEmail = $userInfo['email'];
            $githubAvatarUrl = $userInfo['avatar_url'];
    
            // Kullanıcı bilgilerini session'a kaydet
            $_SESSION['github_username'] = $githubUsername;
            $_SESSION['github_email'] = $githubEmail;
            $_SESSION['avatar_url'] = $githubAvatarUrl;
    
            // Kullanıcı bilgilerini veritabanına kaydet
            // Bu kısmı istediğiniz şekilde veritabanınıza uygun şekilde düzenleyin
            $servername = "localhost";
            $username = "kullanici_adi";
            $password = "sifre";
            $dbname = "veritabani_adi";
    
            $conn = new mysqli($servername, $username, $password, $dbname);
    
            if ($conn->connect_error) {
                die("Bağlantı hatası: " . $conn->connect_error);
            }
    
            $sql = "INSERT INTO kullanici_tablosu (github_username, github_email, avatar_url) VALUES ('$githubUsername', '$githubEmail', '$githubAvatarUrl')";
    
            if ($conn->query($sql) === TRUE) {
                echo "Kullanıcı bilgileri başarıyla veritabanına eklendi";
            } else {
                echo "Hata: " . $sql . "<br>" . $conn->error;
            }
    
            $conn->close();
    
            // Başarıyla işlem yapıldıktan sonra ana sayfaya yönlendir
            header('Location: ana_sayfa.php');
            exit;
        } else {
            // GitHub OAuth sayfasına yönlendir
            $oauthUrl = $client->getAuthorizationUrl($githubClientId, $redirectUri, ['user']);
            header('Location: ' . $oauthUrl);
            exit;
        }
    } catch (\Exception $e) {
        echo 'Hata: ' . $e->getMessage();
    }
    ?>