0

I'm having some difficulty understanding how to use the google api with my rails app. I've already setup devise and oauth2 where I can authenticate and create google users.

The problem is that I want to create folders, documents, and spreadsheets on my own account.

So I want my user to click "create document" and I want to create a document, save it to my own Gdrive and share the edit link.

Is there a way to get a permanent oauth2 token for myself and then use it? How would you go about setting that up.

I will have to make sure the scope is setup for drive and docs when authenticating but that's as far as I got while reading up here:

https://github.com/gimite/google-drive-ruby#readme and I'm using this for oauth2 with devise so already have client info: https://github.com/zquestz/omniauth-google-oauth2

I think I have most of the infrastructure but need that extra push to get my own permanent tokens and figure out how to make my own model that will interact with google.

Any help appreciated.

pinoyyid
  • 21,499
  • 14
  • 64
  • 115
prussiap
  • 667
  • 1
  • 7
  • 14
  • It's very simple. Follow the steps at http://stackoverflow.com/questions/19766912/how-do-i-authorise-an-app-web-or-installed-without-user-intervention-canonic – pinoyyid Jul 31 '15 at 15:11
  • I already did that. Not that easy... I'm having issues with a few things. 1. The links in console don't work (i can't go to the link etc.) but I can use the playground and got both the Authorization code and the token and refresh_token. 2. My problem is HOW THE F do I refresh token after. I did follow the https://developers.google.com/accounts/docs/OAuth2WebServer#offline but i still have no idea. Since i'm not using my app what kind of callback would i use to automate the refresh token or check that it's dead and get another token? Ideally i use my existing User (has token etc.) – prussiap Jul 31 '15 at 17:52
  • it really is that easy. If you follow the steps on the SO link I posted, you'll end up with a refresh token. Embed that token in your app and use to to call the POST endpoint described under "Using a refresh token" on the page you linked. THERE ARE NO CALLBACKS! – pinoyyid Jul 31 '15 at 19:49
  • Tip: https://developers.google.com/oauthplayground/ is a really good starting point for leaning the OAuth flows. – William Denniss Jul 31 '15 at 21:03
  • @WilliamDenniss I've already played with oauthplayground. I got my refresh token from that. All the other parts of my app when the token is active work properly as tested. Currently using gems 'omniauth-google-oauth2', 'google_drive', "google-api-client", for normal user sign-in with auth2 to my rails app. BUT it seems like I might need for offline access to use this: https://github.com/googlesamples/identity-toolkit-ruby since it's linked from that google offline page as what they use? I can't re-use my existing oauth2 refresh/offline stuff. Is there a specific library i'm missing? – prussiap Aug 10 '15 at 13:03

0 Answers0