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?
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.
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With