Created
September 8, 2021 06:51
-
-
Save pioz/7f1cad9483cefcb69741d19e65bbfb43 to your computer and use it in GitHub Desktop.
Read Google sheets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # gem install google-apis-sheets_v4 | |
| require 'google/apis/sheets_v4' | |
| scope = Google::Apis::SheetsV4::AUTH_SPREADSHEETS.freeze | |
| spreadsheets_id = '1ga77r2sjPYTSLGh1IXClnGPvdqFAmkRf-Z5akqfpFEo'.freeze | |
| authorizer = Google::Auth::ServiceAccountCredentials.make_creds( | |
| json_key_io: File.open('./credentials.json'), | |
| scope: scope | |
| ) | |
| authorizer.fetch_access_token! | |
| sheets = Google::Apis::SheetsV4::SheetsService.new | |
| sheets.authorization = authorizer | |
| result = sheets.get_spreadsheet_values(spreadsheets_id, 'A1') | |
| puts result.inspect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment