Skip to content

Instantly share code, notes, and snippets.

@AbigailMcP
Created September 21, 2018 11:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AbigailMcP/42337f0f5f08f2fb782c0d2a6801a734 to your computer and use it in GitHub Desktop.
Save AbigailMcP/42337f0f5f08f2fb782c0d2a6801a734 to your computer and use it in GitHub Desktop.
Google Analytics Reporting service authorization
# Create a Google Analytics Reporting service
service = Google::Apis::AnalyticsreportingV4::AnalyticsReportingService.new
# Create service account credentials
credentials = Google::Auth::ServiceAccountCredentials.make_creds(
json_key_io: File.open('path/to/service_account_cred.json'),
scope: 'https://www.googleapis.com/auth/analytics.readonly'
)
# Authorize with our readonly credentials
service.authorization = credentials
$google_client = service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment