我正在使用Google_Service_Gmail()来获取用户的信息。但出现问题“ PHP致命错误:无法在'... / service / Gmail.php'的第84行调用构造函数”
$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();
lib文件中提供的Gmail.php代码为
here is the code of the file in google api php client library
[我建议您使用Gmail快速入门[1]启动代码,以便可以成功检索Gmail服务,使用此对象,您可以访问“ user”属性(即“ Users_Resource” [2]),应用getProfile方法从中获取“ Gmail_Profile” [3],您可以在其中获取电子邮件地址:
$user = $gmail->user;
$email = $user->getProfile("me")->getEmailAddress( );