Google API get detailed revision history for Doc

Viewed 88

I am able to a list of revisions for a Google Doc using the below (using the google-drive3 Rust crate), which gives me the information from the "Activity" tab from a selected file in Google Drive. I would however like the detailed version history that accessed from within an opened Google Doc with file -> Version history -> See version history. As well as the information shown in Google Drive, this also show which parts of the Doc the revision relates too. Is is possible to access the data for this more detailed version history either from the the Google Drive API or the Google Docs API?

let hub = google_drive3::DriveHub::new(
    google_docs1::hyper::Client::builder().build(
        google_docs1::hyper_rustls::HttpsConnectorBuilder::new()
            .with_native_roots()
            .https_or_http()
            .enable_http1()
            .enable_http2()
            .build(),
    ),
    auth,
);
let activity = hub
    .revisions()
    .list("<document id>")
    .doit()
    .await;
for rev in activity.unwrap().1.revisions.unwrap() {
    dbg!(rev);
}
1 Answers

You have to specify which fields (or all) you want to be returned. If you do not specify this, only a default subset of fields is returned to the caller. Google included a Try it! in their documentation, where you can easily test the API calls you are making. This is how this would look in rust:

let activity = hub
    .revisions()
    .list("<document id>")
    .params({"fields":"*"})
    .doit()
    .await;

Additionally, you'll see a screenshot of the version history for a random Google Drive file. Let's find out how we can get the same data we see in the screenshot programmatically by means of the google-drive3 rust crate.

enter image description here

As you can see in the screenshot, we will need to obtain the following data:

  1. Revision datetime: this is the modified_time field in the Revision struct.
  2. Revision author: this is the last_modifying_user field in Revision struct.
  3. Current revision: retrieve all the revisions and sort by modified_time descending so that the first revision is the current version.
  4. Document changes between revisions: Get the id's of two revisions from field id, the document id we already have. Now get both revision contents using the RevisionGetCall. And perform a diff between those files.
Related