I followed below steps to integrate Google Chat API in my project
- Created APP and enabled Google Chat API
- Created service account and stored private key file
- Code for getting credential and calling API
ServiceAccountCredential credential;
string[] Scopes = { "https://www.googleapis.com/auth/chat.bot" };
using (Stream stream = new FileStream(jsonfile, FileMode.Open, FileAccess.Read,
FileShare.Read))
{
credential = (ServiceAccountCredential)
GoogleCredential.FromStream(stream).CreateScoped(Scopes)// Gathers scopes requested
.CreateWithUser("abc@xyz.com").UnderlyingCredential;
}
var service = new HangoutsChatService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "GoogleChatDemoApp",
});
ListSpacesResponse spaceList = service.Spaces.List().Execute();
But getting error like :
Google.Apis.Requests.RequestError Invalid project number. [404]