Skip to content Skip to sidebar Skip to footer

Why Does Drive auth Require Interaction Again

Purpose

This document describes how to interact with the Google Drive API. This enables users to automate file uploading, downloading, and sharing. The documentation site is good. This brief how-to borrows from information technology.

Prerequisites

  • You lot must have a personal Google business relationship or have your Google apps account via Penn Land set-upwards.

Installation

Packet dependencies

Nosotros'll use the googledrive parcel.

              if (!crave(googledrive)){   install.packages("googledrive") }            
              ## Loading required package: googledrive            

Exam the connection to Google Drive

List files

List files in your Google Drive.

              googledrive::drive_find(n_max = 5)            
              ## Using an machine-discovered, buried token. ## To suppress this message, modify your code or options to conspicuously consent to the use of a buried token. ## See irrigate'south "Non-interactive auth" vignette for more details: ## https://gargle.r-lib.org/manufactures/non-interactive-auth.html ## The googledrive package is using a cached token for rog1@psu.edu.            
              ## # A tibble: five x 3 ##   proper name              id                                          drive_resource   ## * <chr>             <chr>                                       <listing>           ## 1 my-test-information      1tHx8QuoE_Zo6PMpbXBl0zWTBaihsJCvTsCLDZmrtf… <named list [34… ## 2 psy-525-test-data 1NDR8cloSMOifX7vwUhmtg6ne_ATfcFYzjhDRcTUML… <named list [34… ## iii psy-525-test-information 1aX2aGWF6tccCCmv1_X2hx-tqC7-Zm10A1EyWlrWH6… <named list [34… ## four test-data         1aCDqmV2wHybSmTS8CshW_2YdA7pV8i9ilmymU6Jd2… <named listing [34… ## five test-data         1Z14ULrUHXtva15WMiKWp1d3KrF2txEExrasF4V0Ar… <named list [34…            

This will initiate the process of authenticating to your Google Drive business relationship. Depending on which Google Bulldoze account you choose (eastward.g., your personal one or a PSU ane associated with your access ID like rog1@psu.edu) in that location volition be different sets of steps.

When y'all come across "Authentication complete. Please close this page and return to R.", you accept finished the authentication procedure. If you accept documents in your Google Drive under the account you chose, you will meet them listed in the console.

Upload files

Let's create a test file then upload it.

              df <- data.frame(name = c("Tom", "Dick", "Harriet"),                  age = c(ten, 15, 20),                  alive = c(FALSE, True, TRUE))  readr::write_csv(df, "tmp.csv")  # Upload tmp.csv as test-data and make it a spreadsheet (test_data <- googledrive::drive_upload(   media = "tmp.csv",   name = "my-525-test-data",   blazon = "spreadsheet" ))            
              ## Local file: ##   * tmp.csv ## uploaded into Bulldoze file: ##   * my-525-test-data: 1KhjNECniCPU572Jh9TuK9H0C2VqAMtm9xRZ0B9MrT9M ## with MIME blazon: ##   * application/vnd.google-apps.spreadsheet            
              ## # A tibble: ane x 3 ##   name             id                                           drive_resource   ## * <chr>            <chr>                                        <listing>           ## i my-525-test-information 1KhjNECniCPU572Jh9TuK9H0C2VqAMtm9xRZ0B9MrT9M <named list [34…            

We now confirm that Google drive knows about it.

              googledrive::drive_find(pattern = "my-525-test-data")            
              ## # A tibble: 1 x three ##   name             id                                           drive_resource   ## * <chr>            <chr>                                        <list>           ## i my-525-test-data 1KhjNECniCPU572Jh9TuK9H0C2VqAMtm9xRZ0B9MrT9M <named list [34…            

It does, and so allow's download it once more.

              new_test <- googledrive::drive_download("my-525-test-data")            
              ## File downloaded: ##   * my-525-test-data ## Saved locally equally: ##   * my-525-test-information.xlsx            

This downloads the file as .xlsx.

Sheets-specific commands

Packet installation

You volition want to install the googlesheets4 parcel to interact with Google sheets.

              if (!require(googlesheets4)){   install.packages("googlesheets4") }            
              ## Loading required package: googlesheets4            
              ##  ## Attaching package: 'googlesheets4'            
              ## The following objects are masked from 'packet:googledrive': ##  ##     request_generate, request_make            

Reading sheets

              gapm_data <- googlesheets4::read_sheet("1U6Cf_qEOhiR9AZqTqS3mbMF3zt2db48ZP5v3rkrAEJY")            
              ## Using an car-discovered, cached token. ## To suppress this bulletin, alter your code or options to conspicuously consent to the utilise of a cached token. ## Run across gargle's "Non-interactive auth" vignette for more details: ## https://gargle.r-lib.org/articles/not-interactive-auth.html ## The googlesheets4 bundle is using a cached token for rog1@psu.edu.            
              ## Reading from 'gapminder'            
              ##                          

The beginning fourth dimension you lot telephone call this command, the packet will ask to confirm your authentication details.

Now, we tin can visualize the information.

              str(gapm_data)            
              ## Classes 'tbl_df', 'tbl' and 'data.frame':    624 obs. of  6 variables: ##  $ state  : chr  "Algeria" "People's democratic republic of algeria" "Algeria" "Algeria" ... ##  $ continent: chr  "Africa" "Africa" "Africa" "Africa" ... ##  $ year     : num  1952 1957 1962 1967 1972 ... ##  $ lifeExp  : num  43.1 45.seven 48.3 51.4 54.5 ... ##  $ pop      : num  9279525 10270856 11000948 12760499 14760787 ... ##  $ gdpPercap: num  2449 3014 2551 3247 4183 ...            
              library(ggplot2) gapm_data %>%   ggplot(.) +   aes(10 = lifeExp, y = land) +   geom_violin()            

nelsonpedularave.blogspot.com

Source: https://psu-psychology.github.io/psy-525-reproducible-research-2020/how_to/interact-with-google-drive.html

Post a Comment for "Why Does Drive auth Require Interaction Again"