Description:
The Gmail API tool allows users to call into specific Gmail account, using the gmailr package on RStudio to utilize various functions and tools. This tool gives users the ability to process large numbers of emails, compiling data into tables to quickly analyze the sender, subject line, body text, etc. Within these categories, other packages can be used to analyze for date, time, sentiment analysis, and word count. You can also attach email lists and use the gmailr package to send emails directly from the RStudio console.
Uses:
Email Collection
Sending Emails
2.Open up the projects in the top left and select New Project
Once a New Project is selected and you pick a name, navigate to APIs and services .Search for the Gmail API, select, and Enable
Next, proceed back to the cloud console and select OAuth Consent Screen. Create an app as external. When creating the app, keep naming consistent and use your email for all developer information. Adding a logo or domain is not necessary. Add any emails to test users that you would like to use for your API. Complete your app.
Head to the Credentials tab on the left of your screen. Select “Create Credentials” and select “OAuth client ID” This will create a key and secret for use in RStudio. Application app is a Web Application and keep naming consistent. Under Authorized redirect URIs, Add URI and use the link http://localhost:1410/
Once these credentials have been created, it will generate an ID and Secret, which will be used to copy into RStudio at a later time.
key1 <- "XXXXXXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXX.apps.googleusercontent.com"
secret1 <- "XXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXX"
gm_auth_configure(key = key1, secret = secret1)
# gm_auth()
Sending Emails:
Establish recipients, subject line, body, and attachments in the console
# tester <-
# gm_mime() %>%
# gm_to("asayj@xavier.edu") %>%
# gm_from("pbont2019@gmail.com") %>%
# gm_subject("Assignment 5") %>%
# gm_text_body("Attached is my submission for Assignment 5")%>%
# gm_attach_file("assignment5.Rmd")
# Verify it looks correct
# gm_create_draft(tester)
# Send draft directly from RStudio
# gm_send_message(tester)
Reading Emails:
Gain email ids and view directly in R, or export as .csv for later analysis
#set filter
# email_filter <- 'label: College Mail)'
#set number to collect
# num_emails_to_get <- 20
#run gm_messages function with filter, number to collect you just set
# parker_emails <- gm_messages(search=email_filter, num_results = num_emails_to_get)
#view what you've collected - list of message IDs and Thread IDs
# parker_emails
#Centralize Message Ids
# ids = gmailr::gm_id(parker_emails, what="message_id")
#use gm_message function to view data for single email
# msg<-gm_message("16a708aa08eef24e", user_id = "me", format = c("full", "metadata",
# "minimal", "raw"))