• 23-03-2025, 01:00:38
    #1
    PHP vs html ile bir site yapıyorum ama bir türlü Google ile oturum açmayı ayarlayamadım. Yardımcı olabilecek yada ben burdan yaptım diyen var mı
  • 23-03-2025, 01:03:11
    #2
    Google ile oturum açmayı PHP'de ayarlamak için aşağıdaki adımları takip edebilirsin:

    1. Google OAuth 2.0 Kimlik Bilgilerini Al

    Google Cloud Console adresine giderek bir proje oluştur.

    “Kimlik Bilgileri” sekmesine gir ve “OAuth 2.0 İstemci Kimliği” oluştur.

    Yetkili yönlendirme URI'sini (örneğin: http://localhost/callback.php) eklemeyi unutma.


    2. Google API PHP Kütüphanesini Kur

    Google API istemcisi için aşağıdaki komutu kullan:

    composer require google/apiclient

    3. PHP Kodu ile Google Girişini Ayarla

    config.php (Google API yapılandırması)

    require 'vendor/autoload.php';

    $client = new Google_Client();
    $client->setClientId('GOOGLE_CLIENT_ID');
    $client->setClientSecret('GOOGLE_CLIENT_SECRET');
    $client->setRedirectUri('http://localhost/callback.php');
    $client->addScope('email');
    $client->addScope('profile');

    index.php (Giriş Butonu)

    <?php
    require 'config.php';
    $login_url = $client->createAuthUrl();
    ?>
    <a href="<?= $login_url ?>">Google ile Giriş Yap</a>

    callback.php (Google'dan Dönüş)

    <?php
    require 'config.php';

    if (isset($_GET['code'])) {
    $token = $client->fetchAccessTokenWithAuthCode($_GET['code']);
    $client->setAccessToken($token);

    $oauth2 = new Google_Service_Oauth2($client);
    $userInfo = $oauth2->userinfo->get();

    // Kullanıcı bilgileri
    echo "Ad: " . $userInfo->name . "<br>";
    echo "E-posta: " . $userInfo->email;
    }
  • 23-03-2025, 01:04:52
    #4
    @Patroen;
    2. Google API PHP Kütüphanesini Kur

    Google API istemcisi için aşağıdaki komutu kullan:

    composer require google/apiclient. Bunu yapamadım host ta yapmıyor
  • 23-03-2025, 01:08:36
    #5
    YbAloryan adlı üyeden alıntı: mesajı görüntüle
    @Patroen;
    2. Google API PHP Kütüphanesini Kur

    Google API istemcisi için aşağıdaki komutu kullan:

    composer require google/apiclient. Bunu yapamadım host ta yapmıyor
    Hangi frameworkwork'u kullanıyorsunuz hocam
  • 23-03-2025, 01:10:42
    #6
    Patroen adlı üyeden alıntı: mesajı görüntüle
    Hangi frameworkwork'u kullanıyorsunuz hocam
    Herkese Çok teşekkür ederim google auth kullanarak ssh gerek kalmadan hallettim