Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google auth2 API has missing timezone info?

recently I've started using http://code.google.com/p/google-api-php-client/ (Google OAuth2) for my web app. However I draw a blank because I cannot read the timezone for my user. I tried enter it somehow on my Google account page but I didn't found any such field. Does anybody know if Google really offer such information and if so how can I set it to my account for example?

like image 974
Valentin Avatar asked Aug 13 '12 13:08

Valentin


2 Answers

The closest thing available to you is the timezone available on your Google calendar. Check the 'General' tab on your calendar settings page: https://www.google.com/calendar

Now, you can request access to the user's calendar while you're authenticating them to your service. Use the scope "https://www.googleapis.com/auth/calendar" (docs)

When you're authenticated, you can request the calendar you're interested in. I guess the user's primary calendar is your best bet.

Finally, each calendar has settings with a timeZone property.

Here's sample code for the Google API PHP client.

like image 77
johnnycardy Avatar answered Oct 13 '22 11:10

johnnycardy


As of March 21, 2013 Google is not providing this information in their response to the userinfo.profile endpoint -- even though they claim that they do.

This documentation claims that timezone is available: https://developers.google.com/accounts/docs/OAuth2Login?hl=en#userinfocall

However, the current implementation only returns the following data:

  • id
  • email
  • verified_email
  • name
  • given_name
  • family_name
  • link (to G+ profile, if available)
  • gender
  • birthday
  • locale
  • hd (appears to be the Google Apps domain, if relevant)

Note that "birthday" and "hd" are not listed in the current documentation on the page listed above. I am verifying these fields from real-world responses I'm receiving from the endpoint.

The best approach for getting timezone at the moment is probably to use JavaScript (to retrieve the timezone from the user's browser). This StackOverflow answer explains how to do so:

Getting the client's timezone in JavaScript

Unfortunately, this would have to occur as a secondary action, meaning you'd have to add this data to your database separately from the data retrieved from the endpoint. One trick to consider is capturing the timezone offset on the page where you initiate the endpoint request, and then appending the timezone offset value to the "state" value in your OAuth request. This value will then be returned on the callback, and you could extract and add it to the other profile information that was returned during the same procedure in which you write to your database.

like image 44
b.rad Avatar answered Oct 13 '22 11:10

b.rad