I’m working on an iOS app that needs to fetch revision info for Google Drive documents. The tricky part is I’m trying to get this data for files the user doesn’t own.
My main goal is to find out when the document was last changed. Is there a way to get just the timestamp of the most recent revision? I’ve looked through the API docs but I’m not sure which endpoint to use.
Has anyone done something similar before? Any tips on how to set this up in Swift would be super helpful. I’m new to working with Google’s APIs so I’m a bit lost.
I’ve implemented something similar in my app recently. The Files:get method works, but if you need more detailed revision info, consider using the Revisions:list endpoint. It provides a chronological list of revisions, including timestamps and other metadata. Just be aware that accessing revision history for files not owned by the user may require additional permissions. Make sure to handle potential authorization errors gracefully in your code. Also, caching the revision data locally can improve performance if you’re dealing with frequent checks on the same documents.
From my experience integrating the Google Drive API with iOS, I’ve found that while the Files:get method gives the modifiedTime, the Revisions:list endpoint might better serve your need for a concise response that only returns the latest revision’s timestamp. The example below in Swift demonstrates a lean approach using Revisions:list:
let service = GTLRDriveService()
service.authorizer = // Set your authorization
let query = GTLRDriveQuery_RevisionsList.query(withFileId: fileId)
query.fields = "revisions(modifiedTime)"
query.pageSize = 1
query.orderBy = "modifiedTime desc"
service.executeQuery(query) { (ticket, result, error) in
if let revision = (result as? GTLRDrive_RevisionList)?.revisions?.first {
let lastModified = revision.modifiedTime?.date
// Process lastModified as needed
}
}
This minimizes data transfer and focuses on the essential timestamp. Ensure that you have handled the necessary permission scopes, as accessing revisions on non-owned files may require extra permissions.
hey man, i’ve dealt with this before in my app. you wanna use the Files:get method in the Drive API. it’ll give u the modifiedTime field which is what ur after. just make sure u got the right scopes set up in ur auth. good luck with the project!