我有一个移动应用程序,用于处理Google帐户的登录和服务身份验证,响应数据包括:access_token,id_token,refresh_token和serverauthcode。它将这些数据传递给Web服务器。
如何使用这些数据直接将它们设置为Google_Client对象,而无需重定向网址和服务身份验证,因为该作业已在移动应用上完成。谢谢!
These are my code:
function accessService(){
$client_obj = $this->googleAccessToken();
$service = new Google_Service_Calendar($client_obj);
$calendarId = 'primary';
$optParams = array(
'maxResults' => 10,
'orderBy' => 'startTime',
'singleEvents' => TRUE,
'timeMin' => date('c'),
);
$results = $service->events->listEvents($calendarId, $optParams);
print_r($results);
//Im getting Error here in this part
// Uncaught exception 'Google_Service_Exception' with message '{
//"error": "unauthorized_client",
//"error_description": "Unauthorized"}
}
function googleAccessToken(){
$idtoken = 'id_token_from_app';
$refreshtoken = 'refresh_token_from_app';
$access_token = 'access_token_from_app';
$credentials=array('id_token'=>$idtoken,'refresh_token'=>$refreshtoken,'access_token'=>$access_token);
$client = new Google_client();
$client->setApplicationName('CalendarApp');
$client->setAuthConfig('path_to_my_client_secret.json');
$client->setAccessToken(json_encode($credentials));
return $client;
}