4
5

More than 1 year has passed since last update.

Google Keepの一覧を取得するPythonスクリプト

Last updated at Posted at 2022-11-13

概要

gkeepapiを使いKeepのオブジェクトを取得する方法について調査した。
理由はGoogleKeepは一覧性が乏しく、タイトルとノートの一覧を取得しかった。

gkeepapiとは

Google非公式のAPI。Pythonで記述しKeepの情報を取得できる。認証はgpsoauthのライブラリを利用している。
公式ではエンタープライズ向けのみで一般ユーザーへAPIを提供していない。

準備

pip install gkeepapi

コード

import gkeepapi
import json

# Googleアカウント情報(Gmailアドレスとパスワード)の指定 
credential_path = 'C:\\xxxxxxxxxxx\\gcredential.json'
credential = json.load(open(credential_path))
email = credential["email"]
password = credential["password"] # ドキュメントではアカウントの二段階認証を有効にし、アプリパスワードの設定を推奨

# インスタンスの生成
keep = gkeepapi.Keep()

# 認証
keep.login(email, password)

# ノートの取得(ノートの作成順に)
gnotes = sorted(keep.all(), key=lambda x: x.timestamps.created)

# コンソールへ表示
for gnote in gnotes:
    print("Created timestamps: " + gnote.timestamps.created.strftime('%Y-%m-%d %H:%M:%S'))
    print("id   : " + gnote.id)
    print("Title: " + gnote.title)
    print("Text : " + gnote.text)
    print("-------------------------------")

gcredential.json
{
    "email": "user@gmail.com",
    "password": "password"
}

備忘

少し気になる点や調査不足の備忘

  • プライバシーポリシーがドキュメントに不明記で、セキュリティ面の問題がないか気になる。
  • ログイン失敗時に警告が来ない理由が不明。UIからのログインでは、失敗時にGoogleからの警告メールやプッシュ通知が来るので、APIでも同じく警告が来るのではと考えていた。
  • gpsoauthなどのOAuth認証についての理解が浅く勉強が必要と感じた。
4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5