0

After adding scope "https://www.googleapis.com/auth/calendar.readonly" causing the below error.

$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'));

Error received is

Fatal error: Uncaught exception 'Google_ServiceException' with message 'Error calling GET https://www.googleapis.com/oauth2/v2/userinfo: (401) Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.' in C:\xampp\htdocs\bvs\online-payment\src\io\Google_REST.php:66 Stack trace: #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} thrown in C:\xampp\htdocs\bvs\online-payment\src\io\Google_REST.php on line 66

Nikolai Shevchenko
  • 7,083
  • 8
  • 33
  • 42
  • If you try to open the URL https://www.googleapis.com/oauth2/v2/userinfo with your browser, it returns the same error ("Request is missing required authentication credential. ..."). So the issue most likely come from the application configuration. Also have a look to that question: https://stackoverflow.com/questions/24442668/google-oauth-api-to-get-users-email-address? Depending on what you are trying to achieve, you might be also be interested by this: https://www.bearer.sh/integrations/13/google-calendar-api – Frenchcooc Dec 04 '19 at 09:07

1 Answers1

0

The official Google documentation, specifies the syntax for the scope setting as:

 $gClient->setScopes(Google_Service_Calendar::CALENDAR_READONLY);
ziganotschka
  • 25,866
  • 2
  • 16
  • 33