oauth2-google icon indicating copy to clipboard operation
oauth2-google copied to clipboard

Timezone is missing

Open dineshoctal opened this issue 5 years ago • 3 comments

Hello,

Is there any way to get the timezone. I and using google calendar and I want the time zone when we access the token.

Thanks,

dineshoctal avatar Jul 23 '20 11:07 dineshoctal

It might be available in $user->toArray().

If you can point me to the documentation that shows where the timezone information would be made available?

shadowhand avatar Jul 23 '20 15:07 shadowhand

I use to like this and it's working

public function GetUserCalendarTimezone($access_token) { $url_settings = 'https://www.googleapis.com/calendar/v3/users/me/settings/timezone';

	$ch = curl_init();		
	curl_setopt($ch, CURLOPT_URL, $url_settings);		
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);	
	curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer '. $access_token));	
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);	
	$data = json_decode(curl_exec($ch), true); //echo '<pre>';print_r($data);echo '</pre>';
	$http_code = curl_getinfo($ch,CURLINFO_HTTP_CODE);		
	if($http_code != 200) 
		throw new Exception('Error : Failed to get timezone');

	return $data['value'];
}

dineshoctal avatar Jul 24 '20 11:07 dineshoctal

That looks like a perfect solution for your need!

Including such code in this package could be useful, as a separate piece of functionality. I would welcome a PR for it.

shadowhand avatar Jul 24 '20 15:07 shadowhand