设置范围日历。只读会导致Google登录错误

问题描述 投票:0回答:1

添加范围“ https://www.googleapis.com/auth/calendar.readonly”后导致以下错误。

$gClient = new Google_Client();     
$gClient->setApplicationName('Login');
$gClient->setClientId($google_client_id);
$gClient->setClientSecret($google_client_secret);
$gClient->setRedirectUri($google_redirect_url);
$gClient->setScopes(array('https://www.googleapis.com/auth/calendar.readonly'));

收到错误是

致命错误:消息为“调用GET https://www.googleapis.com/oauth2/v2/userinfo时出错”的未捕获异常'Google_ServiceException':(401)请求缺少必需的身份验证凭据。预期的OAuth 2访问令牌,登录cookie或其他有效的身份验证凭据。参见https://developers.google.com/identity/sign-in/web/devconsole-project。在C:\ xampp \ htdocs \ bvs \ online-payment \ src \ io \ Google_REST.php:66堆栈跟踪中:#0 C:\ xampp \ htdocs \ bvs \ online-payment \ src \ io \ Google_REST.php(36 ):Google_REST :: decodeHttpResponse(Object(Google_HttpRequest))#1 C:\ xampp \ htdocs \ bvs \ online-payment \ src \ service \ Google_ServiceResource.php(177):Google_REST :: execute(Object(Google_HttpRequest))#2 C:\ xampp \ htdocs \ bvs \ online-payment \ src \ contrib \ Google_Oauth2Service.php(37):Google_ServiceResource-> __ call('get',Array)#3 C:\ xampp \ htdocs \ bvs \ online-payment \ login.php(49):Google_UserinfoServiceResource-> get()#4 {main}放在C:\ xampp \ htdocs \ bvs \ online-payment \ src \ io \ Google_REST.php,第66行

google-calendar-api google-login
1个回答
0
投票

官方Google documentation,将范围设置的语法指定为:

 $gClient->setScopes(Google_Service_Calendar::CALENDAR_READONLY);
© www.soinside.com 2019 - 2024. All rights reserved.