Skip to content

Instantly share code, notes, and snippets.

@bipoza
Last active September 29, 2023 08:02
Show Gist options
  • Save bipoza/b623814dfa0e9c9c2f35585458d29e8f to your computer and use it in GitHub Desktop.
Save bipoza/b623814dfa0e9c9c2f35585458d29e8f to your computer and use it in GitHub Desktop.
Google Login with Javascript
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Hello Analytics - A quickstart guide for JavaScript</title>
</head>
<body>
<h1>GOOGLE LOGIN</h1>
<script>
var CLIENT_ID = 'YOUR_CLIENT_ID';
window.onload = function () {
const client = google.accounts.oauth2.initTokenClient({
client_id: CLIENT_ID,
scope:
'https://www.googleapis.com/auth/analytics.readonly https://www.googleapis.com/auth/analytics.edit',
callback: (response) => {
console.log('response: ', response.access_token);
},
});
client.requestAccessToken();
};
</script>
<script src="https://accounts.google.com/gsi/client" async></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment