![](/img/trans.png)
[英]ScriptResources Error : This is an invalid script resource request
[英]Google chat - Invalid space resource name in request
有人可以幫我解決“請求中的空間資源名稱無效”。 錯誤?
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:\TestGoogleChat\Program.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 Workspace 開發者預覽版計划的一部分提供,該計划授予對某些功能的早期訪問權限。
由於此方法不完全可用,這意味着不會使用此方法生成客戶端庫。 如果您確實有權訪問該方法,則需要自己發送請求。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.