Friday, 27 September 2019

How to make Login with Google Account using PHP



Now a days in the world of internet, as we know social media is an very import part of any web based application. So if your web application has provide feature like login with social media, then it will be gaining more new users to your web application. So, in this post we have share tutorial on how to login or sign in or register with Google Account in your PHP web application. Here we will make system in which user can login with their Google account into your website.

For login with Google Account using PHP, Google has provide Google OAuth API, which is very easy and helpful to you for implement login using Google account into your Website. Google Login API has provide rights to user to login into the website by using their Google account credential without register on that particular website. By using this feature, your website will gain more subscriber, this is because in current days most of all users have a Google Account, so they can login with their Google Account without sign in on your website.

In this tutorial, we will use Google OAuth Login API, this API give permission to users to login with their existing Google accounts to your website. Below you can find how to integrate Google Login API in your PHP website and you can also find the process how to get API key and how to integrate Google Client Library in your existing PHP library for Login.





Get Google API Credential


First we need to get Google API keys, for this first you have Google Account. So, login into your Google Account and follow below step.

1 - Go to https://console.developers.google.com/ this link.
2 - After this click on Create New Project link for create new project.


3 - Enter Project Name and click on Create button.

4 - Once you have create new project then you can see your project list on web page.

5 -After this click on Google API logo for go to home page.





6 - Once you have redirect to home page then select project from the project select box.


7 - After click on project select box, then one modal will popup and under this you can find list of project, so select your project.


8 - Now from left menu, you have to click on OAuth consent screen.
9 - Once you have click on OAuth consent screen, then one page will load, here you have to define application name and after this click on save button.


10 - When you have click on save button, then after page will redirect another page, and here you have to click on Create credential button, so one drop down menu will appear and from this you have to select OAuth client ID.


11 - After click on OAuth client ID menu then you have redirect to another page, and here you can find different Application type.


12 - From different Application type option, you have to select Web application. Once you have select Web application option, then one form will appear on web page. Here you have to define Name and you have also define Authorized redirect URIs field and lastly click on Create button.


13 - Once you have click on create button, then you can get your Client ID and your client secret key. You have to copy both key for future use for implement Login using Google account using PHP.


Download Google API Client Library for PHP


After getting Google API key, now we need to download Google API Client Library for PHP. For this we have to go command prompt and first type composer command, after this we need to run following command.


composer require google/apiclient:"^2.0"


This command will download Google API Client Library for PHP in your define directory. Now we have proceed for PHP code for how to use Google API Client Library for login using Google account with PHP.

config.php



<?php

//config.php

//Include Google Client Library for PHP autoload file
require_once 'vendor/autoload.php';

//Make object of Google API Client for call Google API
$google_client = new Google_Client();

//Set the OAuth 2.0 Client ID
$google_client->setClientId('1034286712318-kv0gapfqro1aijq84ed72r4aqqs8nan8.apps.googleusercontent.com');

//Set the OAuth 2.0 Client Secret key
$google_client->setClientSecret('Dzq5Xd3olizoZkKjk_SJCWQ1');

//Set the OAuth 2.0 Redirect URI
$google_client->setRedirectUri('http://localhost/tutorial/php-login-using-google-demo/index.php');

//
$google_client->addScope('email');

$google_client->addScope('profile');

//start session on web page
session_start();

?>


index.php



<?php

//index.php

//Include Configuration File
include('config.php');

$login_button = '';

//This $_GET["code"] variable value received after user has login into their Google Account redirct to PHP script then this variable value has been received
if(isset($_GET["code"]))
{
 //It will Attempt to exchange a code for an valid authentication token.
 $token = $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);

 //This condition will check there is any error occur during geting authentication token. If there is no any error occur then it will execute if block of code/
 if(!isset($token['error']))
 {
  //Set the access token used for requests
  $google_client->setAccessToken($token['access_token']);

  //Store "access_token" value in $_SESSION variable for future use.
  $_SESSION['access_token'] = $token['access_token'];

  //Create Object of Google Service OAuth 2 class
  $google_service = new Google_Service_Oauth2($google_client);

  //Get user profile data from google
  $data = $google_service->userinfo->get();

  //Below you can find Get profile data and store into $_SESSION variable
  if(!empty($data['given_name']))
  {
   $_SESSION['user_first_name'] = $data['given_name'];
  }

  if(!empty($data['family_name']))
  {
   $_SESSION['user_last_name'] = $data['family_name'];
  }

  if(!empty($data['email']))
  {
   $_SESSION['user_email_address'] = $data['email'];
  }

  if(!empty($data['gender']))
  {
   $_SESSION['user_gender'] = $data['gender'];
  }

  if(!empty($data['picture']))
  {
   $_SESSION['user_image'] = $data['picture'];
  }
 }
}

//This is for check user has login into system by using Google account, if User not login into system then it will execute if block of code and make code for display Login link for Login using Google account.
if(!isset($_SESSION['access_token']))
{
 //Create a URL to obtain user authorization
 $login_button = '<a href="'.$google_client->createAuthUrl().'"><img src="sign-in-with-google.png" /></a>';
}

?>
<html>
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>PHP Login using Google Account</title>
  <meta content='width=device-width, initial-scale=1, maximum-scale=1' name='viewport'/>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
  <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
  
 </head>
 <body>
  <div class="container">
   <br />
   <h2 align="center">PHP Login using Google Account</h2>
   <br />
   <div class="panel panel-default">
   <?php
   if($login_button == '')
   {
    echo '<div class="panel-heading">Welcome User</div><div class="panel-body">';
    echo '<img src="'.$_SESSION["user_image"].'" class="img-responsive img-circle img-thumbnail" />';
    echo '<h3><b>Name :</b> '.$_SESSION['user_first_name'].' '.$_SESSION['user_last_name'].'</h3>';
    echo '<h3><b>Email :</b> '.$_SESSION['user_email_address'].'</h3>';
    echo '<h3><a href="logout.php">Logout</h3></div>';
   }
   else
   {
    echo '<div align="center">'.$login_button . '</div>';
   }
   ?>
   </div>
  </div>
 </body>
</html>


logout.php



<?php

//logout.php

include('config.php');

//Reset OAuth access token
$google_client->revokeToken();

//Destroy entire session data.
session_destroy();

//redirect page to index.php
header('location:index.php');

?>


So, this is complete process for How to use Google API Client library for PHP Login by using Google account.

58 comments:

  1. Sir I want source code please provide me source code of How to make Login with Google Account using PHP

    ReplyDelete
  2. i can not dowload by composer.can you make video support for using composer.thanks you .

    ReplyDelete
    Replies
    1. just google composer and there you can find all the info.

      Delete
    2. download composer and install it, after installing run as video guide

      Delete
  3. al error: Uncaught GuzzleHttp\Exception\RequestException: cURL error 60: SSL certificate problem: unable to get local issuer certificate (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) in D:\wamp64\www\mobiles\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php on line 201
    ( ! ) GuzzleHttp\Exception\RequestException: cURL error 60: SSL certificate problem: unable to get local issuer certificate (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) in D:\wamp64\www\mobiles\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php on line 201
    Call Stack
    # Time Memory Function Location
    1 0.0002 407368 {main}( ) ...\google_login.php:0
    2 0.0014 424776 Google_Client->fetchAccessTokenWithAuthCode( ) ...\google_login.php:14
    3 0.0495 526256 Google\Auth\OAuth2->fetchAuthToken( ) ...\Client.php:195
    4 0.0502 603600 Google\Auth\HttpHandler\Guzzle6HttpHandler->__invoke( ) ...\OAuth2.php:502
    5 0.0502 603600 GuzzleHttp\Client->send( ) ...\Guzzle6HttpHandler.php:34
    6 0.2485 642968 GuzzleHttp\Promise\RejectedPromise->wait( ) ...\Client.php:106



    show This Error Please Help Me out

    ReplyDelete
    Replies
    1. You have an invalid SSL certificate, or you configured the Oauth client credentials with HTTPS instead of HTTP

      Delete
    2. I think you need an https website for that

      Delete
    3. i have another apprrocahe it works for me
      open vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php

      and change this in if and else both conditions.

      $conf[CURLOPT_SSL_VERIFYHOST] = 2;
      $conf[CURLOPT_SSL_VERIFYPEER] = true;

      to this

      $conf[CURLOPT_SSL_VERIFYHOST] = 0;
      $conf[CURLOPT_SSL_VERIFYPEER] = FALSE;
      it's a temporary solution if you upated this file the changes will lost

      Delete
  4. Thanks, it was easy to implement in my project and I don't get any mistakes, greetings from Colombia.

    ReplyDelete
  5. Hi,

    i'm be able to validate against google with your code. Google returns to me a code:

    Part of the code: 4/vQGVOcq00o0eYuvj_zWJnR-C3LVQmD7H1YymMZjFyKBa.......

    But the problems is with the line:

    $token = $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);

    It's returns error.... var_dump($token);

    { ["error"]=> string(14) "invalid_client" ["error_description"]=> string(12) "Unauthorized" }

    The aplications works from your demo page.

    can you help me, please?

    ReplyDelete
    Replies
    1. hey, 3 and half years later, getting same error, can you help me

      Delete
  6. when i was writing $_SESSION['user_gender'] its showing error. while all the data from session is correct.

    ReplyDelete
  7. This is really helpful, but there's still one thing I want to know,your CMS does not allow php, how do you cope with this? Or do you send members to another platform for registration?

    ReplyDelete
  8. Thank you thank you very much. you are a great.

    ReplyDelete
  9. vendor/autoload.php) where is it ?

    ReplyDelete
  10. I love this kind of posts. Straight to the Point.

    ReplyDelete
  11. hi sir, i am try same step but not working please help us. Error: redirect_uri_mismatch

    The redirect URI in the request, https://meridosti.com/login-with.php?provider=Google, does not match the ones authorized for the OAuth client. To update the authorized redirect URIs, visit: https://console.developers.google.com/apis/credentials/oauthclient/441673219305-g8irofg7mks7v7i5r0cj7m6pk3g8cd8g.apps.googleusercontent.com?project=441673219305

    ReplyDelete
  12. Replies
    1. For logout, the line $google_client->revokeToken(); should be changed to $google_client->revokeToken($_SESSION[ 'access_token' ]);

      Delete
  13. could you please explain me why this error occur
    Warning: Unsupported declare 'strict_types' in C:\xampp\htdocs\goggleloginfinal\googleapi\vendor\monolog\monolog\src\Monolog\Logger.php on line 1

    ReplyDelete
  14. Warning: Unsupported declare 'strict_types' in C:\xampp\htdocs\goggleloginfinal\googleapi\vendor\monolog\monolog\src\Monolog\Logger.php on line 1

    ReplyDelete
  15. how can we store user data by gmail signin

    ReplyDelete
  16. HI, i followed steps, i got this error, Warning: require_once(vendor/autoload.php): failed to open stream: No such file or directory

    ReplyDelete
  17. Hi, thank you for all, it worked well for me.

    ReplyDelete
  18. Hi I followed same step and this working in local host but same code not working on live server.
    Error: Invalid Grant and Bad request

    ReplyDelete
  19. Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: `POST https://oauth2.googleapis.com/revoke` resulted in a `400 Bad Request` response: { "error": "invalid_request", "error_description": "Bad Request" } in C:\xampp\htdocs\login\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php:111 Stack trace: #0 C:\xampp\htdocs\login\vendor\guzzlehttp\guzzle\src\Middleware.php(66): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response)) #1 C:\xampp\htdocs\login\vendor\guzzlehttp\promises\src\Promise.php(203): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Response)) #2 C:\xampp\htdocs\login\vendor\guzzlehttp\promises\src\Promise.php(156): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), Array) #3 C:\xampp\htdocs\login\vendor\guzzlehttp\promises\src\TaskQueue.php(47): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise\{closure}() #4 C:\xampp\htdocs\login\vendor\guzzlehttp\promises\src\Promise.php(246) in C:\xampp\htdocs\login\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php on line 111

    ReplyDelete
    Replies
    1. In logout.php adjust the following:
      $google_client->revokeToken($_SESSION['access_token']);

      Delete
    2. Thanks you.. logout working now.

      Delete
  20. Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: `POST https://oauth2.googleapis.com/revoke` resulted in a `400 Bad Request` response: { "error": "invalid_token", "error_description": "Token expired or revoked" } in /Applications/XAMPP/xamppfiles/htdocs/Online-Food-Order/LoginGoogle/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:111 Stack trace: #0 /Applications/XAMPP/xamppfiles/htdocs/Online-Food-Order/LoginGoogle/vendor/guzzlehttp/guzzle/src/Middleware.php(66): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response)) #1 /Applications/XAMPP/xamppfiles/htdocs/Online-Food-Order/LoginGoogle/vendor/guzzlehttp/promises/src/Promise.php(203): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Response)) #2 /Applications/XAMPP/xamppfiles/htdocs/Online-Food-Order/LoginGoogle/vendor/guzzlehttp/promises/src/Promise.php(156): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), Array) #3 /Applica in /Applications/XAMPP/xamppfiles/htdocs/Online-Food-Order/LoginGoogle/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php on line 111

    ReplyDelete
  21. Thank you for sharing this, it works splendidly. May I ask how to get the id_token from this? I've been trying to find a way but I'm still at lost.

    ReplyDelete
  22. Fatal error: Uncaught TypeError: Argument 1 passed to Google_AccessToken_Revoke::revokeToken() must be of the type array, string given, called in D:\xampp\htdocs\testloginreg\vendor\google\apiclient\src\Google\Client.php on line 671 and defined in D:\xampp\htdocs\testloginreg\vendor\google\apiclient\src\Google\AccessToken\Revoke.php:51 Stack trace: #0 D:\xampp\htdocs\testloginreg\vendor\google\apiclient\src\Google\Client.php(671): Google_AccessToken_Revoke->revokeToken('ya29.a0AfH6SMCU...') #1 D:\xampp\htdocs\testloginreg\logout.php(8): Google_Client->revokeToken('ya29.a0AfH6SMCU...') #2 {main} thrown in D:\xampp\htdocs\testloginreg\vendor\google\apiclient\src\Google\AccessToken\Revoke.php on line 51

    ReplyDelete
  23. is there a way to login to google and facebook in one application? not just google login or facebook login, but use both?

    ReplyDelete
  24. is this google api complete folder require , this so large , can i add without this folder

    ReplyDelete
  25. This comment has been removed by the author.

    ReplyDelete
  26. What if we want more profile related data like phone number, gender, DOB, etc

    ReplyDelete
  27. Getting error. It says:

    Warning: require_once(vendor/autoload.php): failed to open stream: No such file or directory in D:\bitbucket\google-login\config.php on line 6

    ReplyDelete
  28. Occured this below error how can i solve this anyone help me???

    Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in E:\xampp\htdocs\glogin\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php:67 Stack trace: #0 E:\xampp\htdocs\glogin\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php(67): count(NULL) #1 E:\xampp\htdocs\glogin\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php(107): GuzzleHttp\Handler\CurlFactory->release(Object(GuzzleHttp\Handler\EasyHandle)) #2 E:\xampp\htdocs\glogin\vendor\guzzlehttp\guzzle\src\Handler\CurlHandler.php(43): GuzzleHttp\Handler\CurlFactory::finish(Object(GuzzleHttp\Handler\CurlHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(GuzzleHttp\Handler\CurlFactory)) #3 E:\xampp\htdocs\glogin\vendor\guzzlehttp\guzzle\src\Handler\Proxy.php(28): GuzzleHttp\Handler\CurlHandler->__invoke(Object(GuzzleHttp\Psr7\Request), Array) #4 E:\xampp\htdocs\glogin\vendor\guzzlehttp\guzzle\src\Handler\Proxy.php(51): GuzzleHttp\Handler\Proxy::GuzzleHttp\Handler\{closure}(Object(GuzzleHttp\Psr7\Request), Array) #5 E:\xampp\htdocs\glogin\vendor\guzzlehttp\guzzle\src\PrepareBodyMiddleware.php(72): GuzzleHttp\Handler\Proxy::GuzzleHttp\Handler\{closure}(Object(GuzzleHttp\Psr7\Request), Array) #6 E:\xampp\htdocs\glogin\vendor\guzzlehttp\guzzle\src\Middleware.php(30): GuzzleHttp\PrepareBodyMiddleware->__invoke(Object(GuzzleHttp\Psr7\Request), Array) #7 E:\xampp\htdocs\glogin\vendor\guzzlehttp\guzzle\src\RedirectMiddleware.php(68): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Request), Array) #8 E:\xampp\htdocs\glogin\vendor\guzzlehttp\guzzle\src\Middleware.php(57): GuzzleHttp\RedirectMiddleware->__invoke(Object(GuzzleHttp\Psr7\Request), Array) #9 E:\xampp\htdocs\glogin\vendor\guzzlehttp\guzzle\src\HandlerStack.php(67): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Request), Array) #10 E:\xampp\htdocs\glogin\vendor\guzzlehttp\guzzle\src\Client.php(268): GuzzleHttp\HandlerStack->__invoke(Object(GuzzleHttp\Psr7\Request), Array) #11 E:\xampp\htdocs\glogin\vendor\guzzlehttp\guzzle\src\Client.php(96): GuzzleHttp\Client->transfer(Object(GuzzleHttp\Psr7\Request), Array) #12 E:\xampp\htdocs\glogin\vendor\guzzlehttp\guzzle\src\Client.php(104): GuzzleHttp\Client->sendAsync(Object(GuzzleHttp\Psr7\Request), Array) #13 E:\xampp\htdocs\glogin\vendor\google\auth\src\HttpHandler\Guzzle6HttpHandler.php(34): GuzzleHttp\Client->send(Object(GuzzleHttp\Psr7\Request), Array) #14 E:\xampp\htdocs\glogin\vendor\google\auth\src\OAuth2.php(492): Google\Auth\HttpHandler\Guzzle6HttpHandler->__invoke(Object(GuzzleHttp\Psr7\Request)) #15 E:\xampp\htdocs\glogin\vendor\google\apiclient\src\Google\Client.php(184): Google\Auth\OAuth2->fetchAuthToken(Object(Google\Auth\HttpHandler\Guzzle6HttpHandler)) #16 E:\xampp\htdocs\glogin\index.php(18): Google_Client->fetchAccessTokenWithAuthCode('4/0AX4XfWiBWewE...') #17 {main} thrown in E:\xampp\htdocs\glogin\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php on line 67

    ReplyDelete
  29. Occur this below error how can i solve this issue. Anyone help me???


    Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in E:\xampp\htdocs\glogin\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php:67 Stack trace: #0 E:\xampp\htdocs\glogin\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php(67): count(NULL) #1 E:\xampp\htdocs\glogin\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php(107): GuzzleHttp\Handler\CurlFactory->release(Object(GuzzleHttp\Handler\EasyHandle)) #2 E:\xampp\htdocs\glogin\vendor\guzzlehttp\guzzle\src\Handler\CurlHandler.php(43): GuzzleHttp\Handler\CurlFactory::finish(Object(GuzzleHttp\Handler\CurlHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(GuzzleHttp\Handler\CurlFactory)) #3 E:\xampp\htdocs\glogin\vendor\guzzlehttp\guzzle\src\Handler\Proxy.php(28): GuzzleHttp\Handler\CurlHandler->__invoke(Object(GuzzleHttp\Psr7\Request), Array) #4 E:\xampp\htdocs\glogin\vendor\guzzlehttp\guzzle\src\Handler\Proxy.php(51): GuzzleHttp\Handler\Proxy::GuzzleHttp\Handler\{closure}(Object(GuzzleHttp\Psr7\Request), Array) #5 E:\xampp\htdocs\glogin\vendor\guzzlehttp\guzzle\src\PrepareBodyMiddleware.php(72): GuzzleHttp\Handler\Proxy::GuzzleHttp\Handler\{closure}(Object(GuzzleHttp\Psr7\Request), Array) #6 E:\xampp\htdocs\glogin\vendor\guzzlehttp\guzzle\src\Middleware.php(30): GuzzleHttp\PrepareBodyMiddleware->__invoke(Object(GuzzleHttp\Psr7\Request), Array) #7 E:\xampp\htdocs\glogin\vendor\guzzlehttp\guzzle\src\RedirectMiddleware.php(68): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Request), Array) #8 E:\xampp\htdocs\glogin\vendor\guzzlehttp\guzzle\src\Middleware.php(57): GuzzleHttp\RedirectMiddleware->__invoke(Object(GuzzleHttp\Psr7\Request), Array) #9 E:\xampp\htdocs\glogin\vendor\guzzlehttp\guzzle\src\HandlerStack.php(67): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Request), Array) #10 E:\xampp\htdocs\glogin\vendor\guzzlehttp\guzzle\src\Client.php(268): GuzzleHttp\HandlerStack->__invoke(Object(GuzzleHttp\Psr7\Request), Array) #11 E:\xampp\htdocs\glogin\vendor\guzzlehttp\guzzle\src\Client.php(96): GuzzleHttp\Client->transfer(Object(GuzzleHttp\Psr7\Request), Array) #12 E:\xampp\htdocs\glogin\vendor\guzzlehttp\guzzle\src\Client.php(104): GuzzleHttp\Client->sendAsync(Object(GuzzleHttp\Psr7\Request), Array) #13 E:\xampp\htdocs\glogin\vendor\google\auth\src\HttpHandler\Guzzle6HttpHandler.php(34): GuzzleHttp\Client->send(Object(GuzzleHttp\Psr7\Request), Array) #14 E:\xampp\htdocs\glogin\vendor\google\auth\src\OAuth2.php(492): Google\Auth\HttpHandler\Guzzle6HttpHandler->__invoke(Object(GuzzleHttp\Psr7\Request)) #15 E:\xampp\htdocs\glogin\vendor\google\apiclient\src\Google\Client.php(184): Google\Auth\OAuth2->fetchAuthToken(Object(Google\Auth\HttpHandler\Guzzle6HttpHandler)) #16 E:\xampp\htdocs\glogin\index.php(18): Google_Client->fetchAccessTokenWithAuthCode('4/0AX4XfWiBWewE...') #17 {main} thrown in E:\xampp\htdocs\glogin\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php on line 67

    ReplyDelete
  30. How to solve this issue???

    Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in E:\xampp\htdocs\googlelogin\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php:67 Stack trace: #0 E:\xampp\htdocs\googlelogin\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php(67): count(NULL) #1 E:\xampp\htdocs\googlelogin\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php(141): GuzzleHttp\Handler\CurlFactory->release(Object(GuzzleHttp\Handler\EasyHandle)) #2 E:\xampp\htdocs\googlelogin\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php(103): GuzzleHttp\Handler\CurlFactory::finishError(Object(GuzzleHttp\Handler\CurlHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(GuzzleHttp\Handler\CurlFactory)) #3 E:\xampp\htdocs\googlelogin\vendor\guzzlehttp\guzzle\src\Handler\CurlHandler.php(43): GuzzleHttp\Handler\CurlFactory::finish(Object(GuzzleHttp\Handler\CurlHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(GuzzleHttp\Handler\CurlFactory)) #4 E:\xampp\htdocs\googlelogin\vendor\guzzlehttp\guzzle\src\Handler\Proxy.php(28): GuzzleHttp\Handler\CurlHandler->__invoke(Object(GuzzleHttp\Psr7\Request), Array) #5 E:\xampp\htdocs\googlelogin\vendor\guzzlehttp\guzzle\src\Handler\Proxy.php(51): GuzzleHttp\Handler\Proxy::GuzzleHttp\Handler\{closure}(Object(GuzzleHttp\Psr7\Request), Array) #6 E:\xampp\htdocs\googlelogin\vendor\guzzlehttp\guzzle\src\PrepareBodyMiddleware.php(72): GuzzleHttp\Handler\Proxy::GuzzleHttp\Handler\{closure}(Object(GuzzleHttp\Psr7\Request), Array) #7 E:\xampp\htdocs\googlelogin\vendor\guzzlehttp\guzzle\src\Middleware.php(30): GuzzleHttp\PrepareBodyMiddleware->__invoke(Object(GuzzleHttp\Psr7\Request), Array) #8 E:\xampp\htdocs\googlelogin\vendor\guzzlehttp\guzzle\src\RedirectMiddleware.php(68): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Request), Array) #9 E:\xampp\htdocs\googlelogin\vendor\guzzlehttp\guzzle\src\Middleware.php(57): GuzzleHttp\RedirectMiddleware->__invoke(Object(GuzzleHttp\Psr7\Request), Array) #10 E:\xampp\htdocs\googlelogin\vendor\guzzlehttp\guzzle\src\HandlerStack.php(67): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Request), Array) #11 E:\xampp\htdocs\googlelogin\vendor\guzzlehttp\guzzle\src\Client.php(268): GuzzleHttp\HandlerStack->__invoke(Object(GuzzleHttp\Psr7\Request), Array) #12 E:\xampp\htdocs\googlelogin\vendor\guzzlehttp\guzzle\src\Client.php(96): GuzzleHttp\Client->transfer(Object(GuzzleHttp\Psr7\Request), Array) #13 E:\xampp\htdocs\googlelogin\vendor\guzzlehttp\guzzle\src\Client.php(104): GuzzleHttp\Client->sendAsync(Object(GuzzleHttp\Psr7\Request), Array) #14 E:\xampp\htdocs\googlelogin\vendor\google\auth\src\HttpHandler\Guzzle6HttpHandler.php(34): GuzzleHttp\Client->send(Object(GuzzleHttp\Psr7\Request), Array) #15 E:\xampp\htdocs\googlelogin\vendor\google\auth\src\OAuth2.php(492): Google\Auth\HttpHandler\Guzzle6HttpHandler->__invoke(Object(GuzzleHttp\Psr7\Request)) #16 E:\xampp\htdocs\googlelogin\vendor\google\apiclient\src\Google\Client.php(184): Google\Auth\OAuth2->fetchAuthToken(Object(Google\Auth\HttpHandler\Guzzle6HttpHandler)) #17 E:\xampp\htdocs\googlelogin\index.php(14): Google_Client->fetchAccessTokenWithAuthCode('4/0AX4XfWgpmyce...') #18 {main} thrown in E:\xampp\htdocs\googlelogin\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php on line 67

    ReplyDelete
  31. Great post. Works perfectly. Thanks. Just 1 question: any idea how robust this process is? Are there known vulnerabilities?

    ReplyDelete
  32. require_once 'vendor/autoload.php';
    อยู่ตรงใหนครับ

    ReplyDelete
  33. The vendor forlder after installing google/apiclient
    has 16000 files with total size more than 75MB
    Is it really all need for login with google?

    ReplyDelete