I have been tearing my hair out on this for several days. I admit, I am not "that kind of programmer" - I write mathematical algorithms and am no web, security or protocol programmer. Thought I would share my current knowledge as it seem this is a somewhat "bitty" topic. Maybe I haven't understood the official documentation but so far I am struggling and I have found various others grappling with what I suspect is still an emerging technology. I'll post these links below in the comments.
As I understand it, there are THREE principle ways of using OAuth 2.0 with Google Drive/Google Spreadsheets which are implemented a little differently.
- For an installed, desktop application <== this post focuses on this
- For a server-side service
- For a web application
For OAuth 2.0 for an installed desktop application there are appear to be TWO ways of doing this. One is using the GoogleWebAuthorizationBroker
and the other is with GoogleAuthorizationCodeFlow
. I can't prove it definitively but it seems the former was deprecated some time in 2013 and the latter is now the preferred approach.
Firstly, does anyone if it is correct that GoogleAuthorizationCodeFlow
is now the preferred way to do it? I did briefly get the GoogleWebAuthorizationBroker
approach working and logged in just once and I was able to run a SpreadsheetsService.Query
but it seems the generated token is only valid an hour and I can't yet figure out how to refresh it. I suspect that GoogleAuthorizationCodeFlow
can manage this.
Secondly, can anyone post any working code for retrieving and updating a specific, named Google Spreadsheet using OAuth 2.0 in C# for a desktop app? I am working on it myself and will post my code if I get it working.