-
Notifications
You must be signed in to change notification settings - Fork 3
Google API setup
chinyakao edited this page Jun 2, 2022
·
1 revision
It uses google-api-client
package which is deprecated. If it is not working, please refer to the google-api-ruby-client
.
- create GCP project
- enable Google Drive API and Google Calendar API
- Button of "Enable APIs and Services" is hard to find
- Configure the OAuth consent screen
- Create a OAuth client ID credential
- The type of project/application's credential choose web application.
- For creating a staging app:
https://<appname-staging>.herokuapp.com/account/login/google_callback
- For local development:
http://localhost:9090/account/login/google_callback
- For getting refresh token:
https://developers.google.com/oauthplayground
- go to oauth play groung
- click setting and check the checkbox:Use your own Oauth credentials
- copy/paste the Client ID and Client secret from step2
- select the scopes we used on the left side (in application/controller/app.rb file line 36)
- click the Authorize APIs
- It will turn back following screen
- Click Exchange authorization code for tokens and you will see the refresh token
- Copy sample file from SurveyMoonbear to your develop google account
- Find the fileID you want to copy (It would return the id in terminal when the quickstart finish. Or find the fileID in the url)
GOOGLE_CLIENT_ID:
GOOGLE_CLIENT_SECRET:
REFRESH_TOKEN:
SAMPLE_FILE_ID:
(follow this when choosing Desktop application in authorization credentials)
-
Install the Google Client Library
gem install google-api-client
- Set up the sample file Create a file named quickstart.rb
- Download the
credentials.json
from GCP Platform This file has fixed format. You cannot change it. -
credentials.json
has yourgoogle client ID
andgoogle client secret
- Run the sample
ruby quickstart.rb
- After typing
ruby quickstart.rb
and linking to the auth page, it would show a code. ==Just copy and paste it in terminal== which you're running. Then, it would write down the token.yaml -
refresh_token
is written in the filetoken.yaml
only one time once it authorizes. Keep this file or you need to delete the authorizaion and try quickstart angain.
(follow this when choosing Desktop application in authorization credentials)
- In
quickstart.rb
, there is a line setting the scope - different scope has different access right( you can also see here)
- use
AUTH_DRIVE
instead ofAUTH_DRIVE_METADATA_READONLY
to get full permissive scope to access all of a user's files, excluding the Application Data folder