googleworkspace / php-samples

PHP samples for Google Workspace APIs
Apache License 2.0
288 stars 347 forks source link

Quickstart, Invalid Scope #49

Closed ghost closed 5 years ago

ghost commented 5 years ago

I got this error in People Api authentication

, i use same credentials in javascript but in php it give me error, Please see the issue behind this and solve this

Fatal error: Uncaught Google_Service_Exception: { "error": { "code": 403, "message": "Request had insufficient authentication scopes.", "errors": [ { "message": "Request had insufficient authentication scopes.", "domain": "global", "reason": "forbidden" } ], "status": "PERMISSION_DENIED" } } in C:\xampp\htdocs\gpeople\vendor\google\apiclient\src\Google\Http\REST.php:118 Stack trace: #0 C:\xampp\htdocs\gpeople\vendor\google\apiclient\src\Google\Http\REST.php(94): Google_Http_REST::decodeHttpResponse(Object(GuzzleHttp\Psr7\Response), Object(GuzzleHttp\Psr7\Request), 'GoogleService...') #1 C:\xampp\htdocs\gpeople\vendor\google\apiclient\src\Google\Task\Runner.php(181): Google_Http_REST::doExecute(Object(GuzzleHttp\Client), Object(GuzzleHttp\Psr7\Request), 'GoogleService...') #2 C:\xampp\htdocs\gpeople\vendor\google\apiclient\src\Google\Http\REST.php(58): Google_Task_Runner->run() #3 C:\xampp\htdocs\gpeople\vendor\google\apiclient\src\Google\Client.php(779): Goo in C:\xampp\htdocs\gpeople\vendor\google\apiclient\src\Google\Http\REST.php on line 118

Here is the code

`<?php require DIR . '/vendor/autoload.php';

/**

// Get the API client and construct the service object. $client = getClient(); $service = new Google_Service_PeopleService($client);

// Print the names for up to 10 connections. $optParams = array( 'pageSize' => 10, 'personFields' => 'names,emailAddresses', ); $results = $service->people_connections->listPeopleConnections('people/me', $optParams);

if (count($results->getConnections()) == 0) { print "No connections found.\n"; } else { print "People:\n"; foreach ($results->getConnections() as $person) { if (count($person->getNames()) == 0) { print "No names found for this connection\n"; } else { $names = $person->getNames(); $name = $names[0]; printf("%s\n", $name->getDisplayName()); } } }`