https://github.com/kozsec/sec_dashboard/blob/main/src/collectors/google_alert.py
Googleアラートを「その都度」で設定すると、山のようにメールが来るこれを取り込む

GmailのAPIは、以下のURLから発行する。
Google Auth Platformで「対象」を開く
公開ステータスを「本番環境」にする

from google_auth_oauthlib.flow import InstalledAppFlow
from google.oauth2.credentials import Credentials
SCOPES = ["<https://www.googleapis.com/auth/gmail.readonly>"]
def main():
**client_id = "xxxxxxxxxxxxx.apps.googleusercontent.com"
client_secret = "xxxxxxxx"**
# Google OAuth Client の設定をメモリ上で作成
client_config = {
"installed": {
"client_id": client_id,
"client_secret": client_secret,
"auth_uri": "<https://accounts.google.com/o/oauth2/auth>",
"token_uri": "<https://oauth2.googleapis.com/token>",
"redirect_uris": ["<http://localhost>"],
}
}
flow = InstalledAppFlow.from_client_config(
client_config,
SCOPES
)
creds = flow.run_local_server(
port=0,
access_type="offline",
prompt="consent"
)
print("Refresh Token:")
print(creds.refresh_token)
if __name__ == "__main__":
main()
settingからSecrets and variableを開いてAction
Repository Secretに取得した3つの値を登録

.github/workflowsフォルダにyamlを作成
secretを読み取って環境変数として使えるようにする

pythonでは、環境変数から読み込み

以上
<aside>
![]()
NAME : こざもん
SNS : X(@koz_sec)
</aside>