我想将登录用户的电子邮件地址保存到 Google 帐户中。我正在使用谷歌日历 API。这是PHP中的代码
$obj = new Google_Client(array('use_objects' => true));
$obj->setApplicationName("");
// Visit https://code.google.com/apis/console to generate your
// oauth2_client_id, oauth2_client_secret, and to register your oauth2_redirect_uri.
$obj->setClientId('');
$obj->setClientSecret('');
$obj->setRedirectUri('');
$obj->setDeveloperKey('');
$obj->setScopes(array('https://www.googleapis.com/auth/calendar','https://www.googleapis.com/auth/userinfo.email','https://www.googleapis.com/auth/userinfo.profile'));
$client = new Google_CalendarService($obj);
$abc = new Google_Oauth2Service($obj);
我设置了恢复电子邮件的范围并使用日历 API,但这不起作用
try{
$user = $abc -> userinfo -> get();
}
catch(Exception $e){
echo "Mail non trovata<br />.";
}
$email = filter_var($user['email'], FILTER_SANITIZE_EMAIL);
print $email;
get() 函数不起作用,我不知道为什么