php login google api

<?php
require_once 'vendor/autoload.php';
 
// init configuration
$clientID = '<YOUR_CLIENT_ID>';
$clientSecret = '<YOUR_CLIENT_SECRET>';
$redirectUri = '<REDIRECT_URI>';
  
// create Client Request to access Google API
$client = new Google_Client();
$client->setClientId($clientID);
$client->setClientSecret($clientSecret);
$client->setRedirectUri($redirectUri);
$client->addScope("email");
$client->addScope("profile");
 
// authenticate code from Google OAuth Flow
if (isset($_GET['code'])) {
  $token = $client->fetchAccessTokenWithAuthCode($_GET['code']);
  $client->setAccessToken($token['access_token']);
  
  // get profile info
  $google_oauth = new Google_Service_Oauth2($client);
  $google_account_info = $google_oauth->userinfo->get();
  $email =  $google_account_info->email;
  $name =  $google_account_info->name;
 
  // now you can use this profile info to create account in your website and make user logged in.
} else {
  echo "<a href='".$client->createAuthUrl()."'>Google Login</a>";
}
?>

5
3
Taemyr 85 points

                                    $composer require google/apiclient:&quot;^2.0&quot;

5 (3 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
php google login login with google php with google identity api google login using php google register api in php google login authentication php user login with google php google api php client PHP Login using Google Account google authentication api php login with google by js and php code google login with rest api in php example goolgle loogin with rest api in php google login using rest api in php google php login login google php php login via google example code integrate php api google ad php how use google-api-php-client google login authentication using php google login php sdk google login in php with source code google login php source code google php login api how to login with google in php how to use google sign in api in php login via google php google api php google api client php from php to google api example google login developers in php google login api in php login google api php connect to google api php method login with google php code example api login google php login with google in php implement google login php google page login php gmail login integration in php google api login php local google sign in php google signin php google logging php login using google account php php sign in with google localhost php login with google google login in php google login php Authenticate Using Google Sign-In with php is google using php google php signin with google php api login with google php google sign up php register with google and facebook php google login api php login api in php how to login using google account in php login google account api php php google oauth login into home page google sigin php php login google google login php setup
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source