Submitting information to Google spreadsheets / Google form

I want to use a google google spreadsheet or form + spreadsheet to collect a response from user R and send it to the distribution table.

Here is the minimal Google form: https://docs.google.com/forms/d/1tz2RPftOLRCQrGSvgJTRELrd9sdIrSZ_kxfoFdHiqD4/viewform

And the attached table: https://docs.google.com/spreadsheets/d/1xemHzTdeqgMuGbsP6oqDYuMu4PymBdw7k7kMC_-Dsi8/edit#gid=102827002

I thought I would use the Jogry Bryan googlesheets package, for example:

library(googlesheets);library(dplyr)
(my_sheets <- gs_ls())

minresp <- gs_title("minimal (Responses)")
minresp %>% gs_add_row(ws = "dat", input = mtcars[20, 1:2]) 

Works great, but if I include the code, and someone else (i.e. who is not me) tries to use the code:

Error in gs_lookup(., "sheet_title", verbose) : 
  "minimal (Responsess)" doesn't match sheet_title of any sheet returned by gs_ls() (which should reflect user Google Sheets home screen).

So, in the vignette, I see there separately:

# Do you need to access a sheet that you don’t have?
# Access to it by key, if you know it!

, , , :

minresp2 <- gs_key("1xemHzTdeqgMuGbsP6oqDYuMu4PymBdw7k7kMC_-Dsi8")

:

Authentication will be used.
Error in gs_lookup(., "sheet_key", verbose) : 
  "1xemHzTdeqgMuGbsP6oqDYuMu4PymBdw7k7kMC_-Dsi8" doesn't match sheet_key of any sheet returned by gs_ls() (which should reflect user Google Sheets home screen).

, Google, , . , / . , spreasheet , URL- , .

, R ( ) .

+4
3

gs_key(YOUR_KEY, lookup = FALSE, visibility = "private"). .

lookup Google Sheet , - . , GitHub.

. ? , yucky - , . . , , , , . "" , , , .

ss <- gs_new("add-row-test", input = head(iris))
#> Sheet "add-row-test" created in Google Drive.
#> Range affected by the update: "A1:E7"
#> Worksheet "Sheet1" successfully updated with 35 new value(s).
#> Worksheet dimensions: 1000 x 26.

:
> "" > - , ,

:

ss_key <- "114cXPTe9whThS3lmpa3neY2vplpUX1hcnM8o8Oo6QtM"
add_row_result <- ss_key %>%
  gs_key(lookup = FALSE, visibility = "private") %>%
  gs_add_row(input = c("can", "you", "hear", "me", "now?"))
#> Authorization will not be used.
#> Worksheets feed constructed with private visibility
#> Row successfully appended.
add_row_result %>%
  gs_read()
#> Accessing worksheet titled "Sheet1"
#> Source: local data frame [9 x 5]
#>
#>   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#>          (chr)       (chr)        (chr)       (chr)   (chr)
#> 1          5.1         3.5          1.4         0.2  setosa
#> 2          4.9           3          1.4         0.2  setosa
#> 3          4.7         3.2          1.3         0.2  setosa
#> 4          4.6         3.1          1.5         0.2  setosa
#> 5            5         3.6          1.4         0.2  setosa
#> 6          5.4         3.9          1.7         0.4  setosa
#> 7          can         you         hear          me    now?
+3

, , Google . @jennybryan - № 126, 148 :

https://github.com/jennybc/googlesheets/issues/148

, , . . ? API. , ! , :

126 ()

+2

, .:)

, , , , . Auth, RGoogleAnalytics.

# client id and secret for google drive ####
client.secret <- "YOUR SECRET"
client.id <- "YOUR ID"

# auth function to get at files in google drive ####
# and implementing it 
Auth <- function(client.id,client.secret) {

  require(httr)

  myapp <- oauth_app("google", client.id,
                     client.secret)
  google.token <- oauth2.0_token(oauth_endpoints("google"), myapp,
                                 scope = "https://www.googleapis.com/auth/drive.file")
  return(google.token)
}


token <- Auth(client.id,
              client.secret)

, , .

+1

Source: https://habr.com/ru/post/1613243/


All Articles