【问题标题】:Accessing google docs revision history through the API using R?使用 R 通过 API 访问谷歌文档修订历史?
【发布时间】:2012-03-20 07:25:11
【问题描述】:

我希望使用 R 下载并分析我的一个 google 文档的修订历史,找出统计数据,例如谁做了多少编辑。

我看到已经有 some ways for 使用 R 访问谷歌文档。

有没有人预先知道(在我继续尝试破解我的方式之前),是否或如何(相当容易地)完成?

谢谢。

【问题讨论】:

    标签: api r google-docs revision-history


    【解决方案1】:

    Google Documents List API 可让您访问修订列表、每个修订的内容、确保为给定更新存储修订的方法等。

    修订列表可能会为您提供所需的信息,但您需要更具体地确定所需的统计信息。请注意,关于谁进行了哪些更改的历史数据似乎有点不完整 - 请参阅API problems with revision history - Google Documents List API | Google Groups

    【讨论】:

      【解决方案2】:

      googledrive 包包含一些可用于此目的的低级 API 函数。例如,我们可以通过以下方式获取一个 Google 文档的修订列表:

      library(googledrive)
      library(tidyverse)
      
      # replace this with the ID of your google doc
      # this doc is private, it wont work for you
      fileId <- "1s0CPFXnMQjZNts6gYAnkcGXGSAgugTupzMf8YeoCbps"
      
      # Get the name of the file and some other metadata
      file <- build_request(
        path = "drive/v3/files/{fileId}",
        method = "GET",
        params = list(
          fileId = fileId,
          fields = "*"
        ),
        token = drive_token()
      )
      file_ret <-  process_response(make_request(file))
      
      # Now for this doc, query the Drive API to get get URLs and other meta-data for all the revisions available to us
      
      req2 <- build_request(
        path = "drive/v2/files/{fileId}/revisions",
        method = "GET",
        params = list(
          fileId = fileId
        ),
        token = drive_token()
      )
      revs2 <-  process_response(make_request(req2))
      
      # See 
      # https://developers.google.com/drive/api/v2/reference/revisions#resource
      # for an explanation of each variable that we have here
      
      # tidy revisions into a dataframe
      revs2_df <-
        map_df(
          revs2$items,
          `[`,
          c(
            "kind",
            "etag" ,
            "id",
            "selfLink"   ,
            "mimeType"     ,
            "modifiedDate",
            "published"   ,
            "lastModifyingUserName"
          )
        )
      # get exportLinks URLs out of its nest
      revs2_export_url <- map_df(revs2$items, "exportLinks")
      # bind together
      revs2_df_bind <- bind_cols(revs2_df, revs2_export_url)
      

      结果包括,对于每个修订,日期、时间、进行修订的用户的姓名,以及将该修订导出到下载文件的 URL:

      # A tibble: 140 x 16
         kind   etag  id    selfLink mimeType modifiedDate published lastModifyingUs… `application/rt…
         <chr>  <chr> <chr> <chr>    <chr>    <chr>        <lgl>     <chr>            <chr>           
       1 drive… "\"H… 28367 https:/… applica… 2017-09-12T… FALSE     Gayoung Park     https://docs.go…
       2 drive… "\"H… 28487 https:/… applica… 2017-09-12T… FALSE     Gayoung Park     https://docs.go…
       3 drive… "\"H… 28862 https:/… applica… 2017-09-13T… FALSE     Gayoung Park     https://docs.go…
       4 drive… "\"H… 29221 https:/… applica… 2017-09-13T… FALSE     Gayoung Park     https://docs.go…
       5 drive… "\"H… 29258 https:/… applica… 2017-09-13T… FALSE     Gayoung Park     https://docs.go…
       6 drive… "\"H… 29434 https:/… applica… 2017-09-13T… FALSE     Gayoung Park     https://docs.go…
       7 drive… "\"H… 29454 https:/… applica… 2017-09-18T… FALSE     Gayoung Park     https://docs.go…
       8 drive… "\"H… 29603 https:/… applica… 2017-09-18T… FALSE     Gayoung Park     https://docs.go…
       9 drive… "\"H… 30108 https:/… applica… 2017-09-18T… FALSE     Gayoung Park     https://docs.go…
      10 drive… "\"H… 30115 https:/… applica… 2017-09-21T… FALSE     Gayoung Park     https://docs.go…
      # ... with 130 more rows, and 7 more variables: `application/vnd.oasis.opendocument.text` <chr>,
      #   `text/html` <chr>, `application/pdf` <chr>, `application/epub+zip` <chr>,
      #   `application/zip` <chr>,
      #   `application/vnd.openxmlformats-officedocument.wordprocessingml.document` <chr>,
      #   `text/plain` <chr>
      

      然后我们可以遍历导出 URL 以下载所有修订版,并比较大小或字数等,最终得到如下图:

      这些图的完整代码在这里:https://gist.github.com/benmarwick/1feaa2b2f0d7bc5f7e97903b8ff92aed

      请注意,通过 API 提供的 Google 云端硬盘修订历史记录存在一些严重限制。例如,

      • 当多个用户同时编辑时,我们只会获得该会话中第一个活动编辑器的名称。其他人没有被捕获。
      • 当在短时间内发生许多修改时,Google 会将这些修改合并为一个修订版,我们无法单独查看它们。我们没有很好的时间分辨率。
      • Google 会删除旧的编辑以节省空间。我们不知道他们对此有何规定。

      【讨论】:

        猜你喜欢
        • 2012-01-31
        • 1970-01-01
        • 2012-12-12
        • 1970-01-01
        • 1970-01-01
        • 2014-05-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多