Skip to content

Instantly share code, notes, and snippets.

@mikepyts
Created April 13, 2019 13: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 mikepyts/2d99e6b6663be7f876100029bb1dc980 to your computer and use it in GitHub Desktop.
Save mikepyts/2d99e6b6663be7f876100029bb1dc980 to your computer and use it in GitHub Desktop.
Authentificate and authorize to Google APIs
// Access scopes
private val accessScope = listOf("https://www.googleapis.com/auth/cloud-platform.read-only")
private var token = "Empty"
// Receive Google OAuth 2 token for API access
private fun authenticateAndAuthorize() {
doAsync {
val googleCredential = GoogleCredential
.fromStream(ctx.assets.open("service-account.json"))
.createScoped(accessScope)
googleCredential.refreshToken()
this@BigQueryAPI.token = googleCredential.accessToken
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment