I have just configured everything in google cloud console, i am using service account as auth method and i download key file as json. But i am getting this error
"Call failed with message: { "message": "Permission denied on resource Space (or it might not exist)", "code": 7, "status": "PERMISSION_DENIED", "details": [] }"
<?php
namespace App\Http\Controllers\Panel;
use App\Http\Controllers\Controller;
use Google\ApiCore\ApiException;
use Google\ApiCore\ValidationException;
use Google\Apps\Meet\V2\Client\SpacesServiceClient;
use Google\Apps\Meet\V2\CreateSpaceRequest;
use Google\Apps\Meet\V2\Space;
class YourControllerName extends Controller
{
public function __construct()
{
}
/**
* @throws ValidationException
*/
public function index()
{
$spacesServiceClient = new SpacesServiceClient([
'credentials' => storage_path('app\google-calendar\credentials.json')
]);
$request = new CreateSpaceRequest();
try {
$response = $spacesServiceClient->createSpace($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
after setting up domain wide delegation and other related configurations on google cloud console this code worked for me
public function index(){
$credentials = (new ServiceAccountCredentials(['https://www.googleapis.com/auth/meetings.space.readonly','https://www.googleapis.com/auth/meetings.space.created']
,base_path("key.json"),
'test@test.com'
));
// Create a client.
$spacesServiceClient = new SpacesServiceClient(['credentials' => $credentials]);
// Prepare the request message.
$request = new CreateSpaceRequest();
// Call the API and handle any network failures.
try {
/** @var Space $response */
$response = $spacesServiceClient->createSpace($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}