Google Off-Line Access and Refresh Token

I don’t know much about using the built-in Oauth2 user-agent flow, but if you get stuck or are interested in manually managing things, this might help you: