Skip to content

Instantly share code, notes, and snippets.

@pioz
Created September 8, 2021 06:51
Show Gist options
  • Select an option

  • Save pioz/7f1cad9483cefcb69741d19e65bbfb43 to your computer and use it in GitHub Desktop.

Select an option

Save pioz/7f1cad9483cefcb69741d19e65bbfb43 to your computer and use it in GitHub Desktop.
Read Google sheets
# 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