Google Meet REST API报错:Space资源权限拒绝或不存在
Google Meet API 创建Space 权限拒绝问题排查
问题描述
已在Google Cloud Console完成所有配置,采用服务账号认证并下载了JSON密钥文件,但调用API创建Space时返回如下错误:
"Call failed with message: { "message": "Permission denied on resource Space (or it might not exist)", "code": 7, "status": "PERMISSION_DENIED", "details": [] }"
相关PHP代码:
<?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()); } } }
解决方案
检查服务账号权限
Google Meet Spaces API创建Space需要特定权限,服务账号必须被授予至少一个相关角色:meet.spaces.create(基础创建权限)- 或
Meet Space Admin等高级角色
前往Google Cloud Console的IAM页面,给服务账号添加对应权限,注意权限生效可能需要几分钟同步时间。
配置域范围委托(Workspace环境)
若在Google Workspace环境下使用服务账号,需启用域范围委托,并在Google Admin Console中授权服务账号访问以下API范围:https://www.googleapis.com/auth/meet.spaces
未配置该委托的话,服务账号无法代表域内用户创建Space。
验证密钥文件有效性
确认storage_path('app\google-calendar\credentials.json')指向的文件存在,且PHP进程拥有读取该文件的权限。可尝试使用绝对路径测试,避免路径解析错误。确认API已启用
再次检查Google Meet Spaces API v2是否已在Google Cloud Console的API库中启用,未启用API会触发权限类错误。添加用户主体模拟
使用服务账号创建Space时,需通过域范围委托模拟一个具体的Workspace用户,否则无法生成归属用户的Space。修改代码添加impersonated_user_email参数:$spacesServiceClient = new SpacesServiceClient([ 'credentials' => storage_path('app/google-calendar/credentials.json'), 'impersonated_user_email' => 'user@your-domain.com' // 替换为域内有效用户邮箱 ]);
内容的提问来源于stack exchange,提问作者Eren Sertkaya
相关产品推荐
相关产品推荐

