I have setup a service account which I am trying to use to access Google Docs API. I keep getting this error
"Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: `GET https://docs.googleapis.com/v1/documents/1G6BnSgWCEWn6a5UYeF1XjJYuXIwHxwlAmOIqHj3rtgU` resulted in a `401 Unauthorized` response:
{
"error": {
"code": 401,
"message": "Request is missing required authentication credential. Expected OAuth 2 (truncated...)"
I have setup the scopes in my admin google workspace account along with the client id... Below is my code:
<?php
require_once 'vendor/autoload.php';
// use Google\Client;
// use GuzzleHttp\Client;
$client = new Google\Client();
$client->setApplicationName('TESTING GOOGLE DOC API');
$client->setAuthConfig('hale-runner-356311-4acd25674408.json');
// $client->useApplicationDefaultCredentials();
$client->setScopes("https://www.googleapis.com/auth/documents.readonly");
$client->setSubject('generated email when creating service account');
$client->setAccessType('offline');
$guzzle = new GuzzleHttp\Client(['base_uri' => 'https://docs.googleapis.com/v1/documents/']);
$response = $guzzle->request('GET', '1G6BnSgWCEWn6a5UYeF1XjJYuXIwHxwlAmOIqHj3rtgU', [
'verify' => false,
]);
var_dump($response);
I kind of feel that I need to pass additional data to my request but don't where to put that, have added it after the "verify => false", still getting the same error....
I really need a guide on this.... I will so much appreciate any info.
Thanks