1

i want to save the email address of the logged user into Google account. I'm working with Google Calendar API. This is the code in 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);

i set the scope to recover the email and also use Calendar API, but this don't work

try{
      $user = $abc -> userinfo -> get();
  }
  catch(Exception $e){
      echo "Mail non trovata<br />.";
  }
  $email = filter_var($user['email'], FILTER_SANITIZE_EMAIL);
  print $email;

the get() function don't work and i don't know why

Chris Morgan
  • 86,207
  • 24
  • 208
  • 215
marzobryant90
  • 33
  • 1
  • 9
  • I doubt you can get it directly like this. You need to setup `clientSecretKey`,`developerKey` & other parameters. And follow the steps as if in https://developers.google.com/oauthplayground/ – Rikesh Jun 20 '13 at 09:53
  • i simple delete the clientID, clientSecret ecc ecc here, in mine app is all declarated! – marzobryant90 Jun 20 '13 at 10:00
  • Ok. Btw what exactly you mean by *don't work* ? What you getting in `$user` ? – Rikesh Jun 20 '13 at 10:04
  • If i remove the try/catch this is the Exception `Uncaught exception 'Google_ServiceException' with message 'Error calling GET ...` – marzobryant90 Jun 20 '13 at 10:09
  • Try catch exception with `} catch (Google_ServiceException $e) {`, & see what is the error. – Rikesh Jun 20 '13 at 10:28
  • `Insufficient Permission` !?!? that's strange because i have done all operation on Google Calendar without this error – marzobryant90 Jun 20 '13 at 10:36
  • Check [this](http://stackoverflow.com/questions/16970917/why-is-google-calendar-api-oauth2-responding-with-insufficient-permission) any other forums you might be missing something. – Rikesh Jun 20 '13 at 10:56

0 Answers0