获取用户电子邮件谷歌日历

时间:2013-06-20 09:48:46

标签: php email google-calendar-api

我想将已登录用户的电子邮件地址保存到Google帐户中。我正在使用Google Calendar 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);

我将范围设置为恢复电子邮件并使用Calendar 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()函数不起作用,我不知道为什么

0 个答案:

没有答案