i am using Google_Service_Gmail() to get the users'info. but getting issue "PHP Fatal error: Cannot call constructor on line 84 in '.../service/Gmail.php'"
$obj = new GoogleOAuth();
$obj->access_token =$access;
$obj->refresh_token = $refresh;//$data['refresh_token'];
$obj->token_type = $tokentype;
$obj->expires_in = 3600;
$arr = array();
$client = new Google_Client($arr);
$client->setApplicationName('Get Email');
$client->setClientId('[CLIENT-ID]');
$client->setClientSecret('[CLIENT-SECRET]');
$client->setRedirectUri('[REDIRECT-URI]');
$client->setScopes(Google_Service_Gmail::GMAIL_READONLY);
$client->setAccessType('offline');
$authUrl = $client->createAuthUrl();
$token = json_encode($obj);
if (!$client->getAccessToken()) {
$client->setAccessToken($token);
}
$gmail = new Google_Service_Gmail($client);
return $gmail->getEmailAddress();
the code of Gmail.php provided in lib files is
here is the code of the file in google api php client library
I suggest you start your code with the Gmail quickstart [1] so you can successfully retrieve the Gmail Service, with this object you can access to the "user" property which is a "Users_Resource" [2], apply the getProfile method to obtain the "Gmail_Profile" [3] from where you can get the email address:
$user = $gmail->user;
$email = $user->getProfile("me")->getEmailAddress( );