# コード

https://github.com/kozsec/sec_dashboard/blob/main/src/collectors/google_alert.py

# 取り込むもの

# GmailのAPI設定

# APIキー取得

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()

# APIキーをGithubに登録

# GithubでSecretを使用

以上

<aside>

ICON.png

Hello world


NAME : こざもん

SNS : X(@koz_sec)

</aside>