I am able to login with Google by PHP. But could not find how to get the login email after login with which the user logged in. It is very important to get the login email. Please help me out. Thanks in advance. I am getting the code google returns after login and the access token. Here is my code:
$client_id = '870872749542-hf3ll1kbpnucn8rm67p2s83h5j890og5.apps.googleusercontent.com';
$client_secret = '_Q4sSVLD90RKZ5H1seRPrw6D';
$redirect_uri = 'http://symmetrix.website/staging/property/gcontacts.php';
$simple_api_key = 'AIzaSyANQX5L0uNzRb2wYOq3t0VHvVLcfoi71Gs';
$max_results = 30;
$auth_code = $_GET["code"];
$fields = array(
'code' => urlencode($auth_code),
'client_id' => urlencode($client_id),
'client_secret' => urlencode($client_secret),
'redirect_uri' => urlencode($redirect_uri),
'grant_type' => urlencode('authorization_code')
);
$post = '';
foreach ($fields as $key => $value) {
$post .= $key . '=' . $value . '&';
}
$post = rtrim($post, '&');
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://accounts.google.com/o/oauth2/token');
curl_setopt($curl, CURLOPT_POST, 5);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
$result = curl_exec($curl);
curl_close($curl);
$response = json_decode($result);
if (isset($response->access_token)) {
$accesstoken = $response->access_token;
}