Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I retrieve user's email from Google

I am using the Google client library in PHP.
I am successfully authenticated.
Missing a simple thing (I added the right scope). How do I retrieve the user's email after I finish the auth process.
Below is what I have:

$client = new Google_Client();
$client->setClientId(MYCLIENTID);
$client->setClientSecret(MYSECRET);
$client->setRedirectUri(SOMEURLINMYSYSTEM);
$service = new Google_Service_Oauth2($client);
$client->addScope(Google_Service_Oauth2::USERINFO_EMAIL);
$client->authenticate($_GET['code']);//I have the right code, and I am being authenticated

//TODO Get from google the user's email ?????????

I am using the PHP library here: https://code.google.com/p/google-api-php-client/wiki/OAuth2

like image 443
Itay Moav -Malimovka Avatar asked May 29 '14 14:05

Itay Moav -Malimovka


People also ask

How do you find out someones Google email?

Type the name of the person and @gmail.com to search for his address. If it's listed in any public website or message board, you have a chance. Type John Smith, @gmail.com, and press Search to retrieve the results.


1 Answers

oops, just found it:

$client = new Google_Client();
$client->setClientId(MYCLIENTID);
$client->setClientSecret(MYSECRET);
$client->setRedirectUri(SOMEURLINMYSYSTEM);
$service = new Google_Service_Oauth2($client);
$client->addScope(Google_Service_Oauth2::USERINFO_EMAIL);
$client->authenticate($_GET['code']);//I have the right code, and I am being authenticated

$client->authenticate($code);
$plus = new Google_Service_Plus($client);
$person = $plus->people->get('me');
var_dump($person);
like image 153
Itay Moav -Malimovka Avatar answered Oct 12 '22 23:10

Itay Moav -Malimovka