{gmailr} で gmail 履歴を取得
gmail のログを R を使って集計したかったのでググったら CRAN にパッケージありました、{gmailr} 。
これを使ったコードが簡単なので以下貼り付けちゃいます。 送信したメール一覧を取得します。gmailkey.json は Google Developers Console から取得してください。
library(gmailr) library(purrr) # Authenticate Gmail access gmail_auth("gmailkey.json", scope = 'read_only') # Create gmail seach query start_date = Sys.Date()-7 # a week ago end_date = Sys.Date() gmail_search_query = paste0("in:sent after:", start_date, "before:", end_date) # Retrieve message id's using the search query ids = id(messages(search = gmail_search_query)) # Get the "To" field using the id's ids %>% map(message) -> msgs msgs %>% map(to) -> tos msgs %>% map(cc.gmail_message) -> ccs msgs %>% map(subject) -> sbjs
以下のレポジトリに置いてあります。
{purrr} も便利すぎて感動モノだったのですが、それはまた今度。