I have built a website and intend users to login with their google account, they will be able to make comments using their google email address on my site.
I have work my way through googles documentation and am now confused.
https://developers.google.com/accounts/
I have managed to get the user to authorise the use of their details and google returns the access token etc in the query string:
access_token
token_type=Bearer
expires_in=3600
My problem is how to get the users email address using the access token. I realise this means making a request to google. But how?
I simply would like help with hopefully a couple of lines of code to go to google and get the users email using my php page. Just the simplest php example if anyone has one?
I have been searching for hours and am now at a loss.
Thanks
In my expereince google client doesn’t give the user email but you can get it using an oath2 response.
once you have the access token you can do this. hope this helps
require_once ‘path_to_your_google_library/Google_Client.php’;
require_once ‘path_to_your_google_library/contrib/Google_Oauth2Service.php’;
$google_instance = new Google_Client();
$oath2 = new Google_Oauth2Service($google_instance);
$oauth_response = $oauth2->userinfo->get();
$email_of_user = $oauth_response[’email’];