Google聊天-请求中的空间资源名称无效



谁能帮我处理一下"请求中无效的空间资源名称" ?错误呢?

  1. 我在Google Cloud中创建了服务帐户/应用程序
  2. 我创建了Google Chat API
  3. 我创建了空间"服务器"并添加我的应用程序到空间
using Google.Apis.Auth.OAuth2;
using Google.Apis.HangoutsChat.v1;
using Google.Apis.Services;
Console.WriteLine("START");
SendMessage("spaces/server", "Hello Jozef");
Console.WriteLine("END");
void SendMessage(string space, string message, string thread = null)
{
try
{
var jsonPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "E://serverapplication-92ed800d27af.json");
using (var stream = new FileStream(jsonPath, FileMode.Open, FileAccess.Read))
{
string[] scopes = new[] { "https://www.googleapis.com/auth/chat.bot" };
var credential = GoogleCredential.FromStream(stream)
.CreateScoped(scopes);
var service = new HangoutsChatService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "ServerApplication"
});
var pubSubMessage = new Google.Apis.HangoutsChat.v1.Data.Message
{
Text = message,
Thread = new Google.Apis.HangoutsChat.v1.Data.Thread() { Name = thread },
Sender = new Google.Apis.HangoutsChat.v1.Data.User() { Name = "ServerApplication", DisplayName = "ServerApplication" },
};
SpacesResource.MessagesResource.CreateRequest req = new SpacesResource.MessagesResource(service).Create(pubSubMessage, space);
var result = req.Execute();
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
}

看来申请表和证书都没问题。什么会导致这个错误?如果我创建了一个"服务器"是否正确?空间和添加这个应用程序吗?

The service chat has thrown an exception.
HttpStatusCode is BadRequest.
Google.Apis.Requests.RequestError
Invalid space resource name in request. [400]
Errors [
Message[Invalid space resource name in request.] Location[ - ] Reason[badRequest] Domain[global]
]
Google.GoogleApiException: The service chat has thrown an exception. HttpStatusCode is BadRequest. Invalid space resource name in request.
at Google.Apis.Requests.ClientServiceRequest`1.ParseResponse(HttpResponseMessage response)
at Google.Apis.Requests.ClientServiceRequest`1.Execute()
at Program.<<Main>$>g__SendMessage|0_0(String space, String message, String thread) in E:TestGoogleChatProgram.cs:line 37

感谢您的任何想法或观察

方法调用错误。所有的方法都需要通过服务对象调用。

这将得到一个空格列表。

var listOfSpaces = service.Spaces.List().Execute();

然后创建消息,将其添加到

var request = service.Spaces.Messages.Create(new Message(), "spaces/{SpaceId}");
var response = request.Execute();
<标题>

空间创建如space .create

文档中所述

开发者预览:作为Google工作空间开发者预览计划的一部分可用,它授予早期访问某些功能的权限。

由于此方法不完全可用,这意味着将不会使用此方法生成客户端库。如果你有访问该方法的权限,你需要自己发送请求。

最新更新