|
import os |
|
import json |
|
from google.oauth2 import service_account |
|
|
|
|
|
service_account_info = os.getenv('GOOGLE_APPLICATION_CREDENTIALS_CONTENT') |
|
|
|
if service_account_info is None: |
|
raise ValueError("サービスアカウントのJSON内容が設定されていません。") |
|
|
|
|
|
service_account_info_dict = json.loads(service_account_info) |
|
|
|
|
|
credentials = service_account.Credentials.from_service_account_info(service_account_info_dict) |
|
|
|
|
|
|
|
from googleapiclient.discovery import build |
|
|
|
chat_service = build('chat', 'v1', credentials=credentials) |
|
|
|
|
|
space_name = 'spaces/your-space-id' |
|
message = { |
|
'text': 'Hello from the Google Chat API!' |
|
} |
|
|
|
response = chat_service.spaces().messages().create( |
|
parent=space_name, |
|
body=message |
|
).execute() |
|
|
|
print('Message sent: ', response) |
|
|