If you're looking to gather data (such as email addresses) using JavaScript, I have a solution for you. This code snippet demonstrates how to receive and display data with an alert message at the end. You can also save this data into a database. It's a comprehensive example that includes a Google Sign-in button.
<html>
<head>
<title>Demo: Capture email address with Google+ Sign-in button</title>
<!-- Import necessary API and client scripts for Google+. -->
<script src = "https://plus.google.com/js/client:platform.js" async defer></script>
</head>
<body>
<!-- Area containing the Google Sign-In button. -->
<div id="gConnect" class="button">
<button class="g-signin"
data-scope="email"
data-clientid="Your_Client_ID"
data-callback="onSignInCallback"
data-theme="dark"
data-cookiepolicy="single_host_origin">
</button>
<!-- Text area to display output data -->
<div id="response" class="hide">
<textarea id="responseContainer" style="width:100%; height:150px"></textarea>
</div>
</div>
</body>
<script>
/**
* Function called after user signs in with Google.
*/
function onSignInCallback(resp) {
gapi.client.load('plus', 'v1', apiClientLoaded);
}
/**
* Initiates an API call upon loading of Google API client.
*/
function apiClientLoaded() {
gapi.client.plus.people.get({userId: 'me'}).execute(handleEmailResponse);
}
/**
* Callback function executed when API client receives a response.
*
* @param resp The API response object containing user email and profile information.
*/
function handleEmailResponse(resp) {
var primaryEmail;
var name;
var gender;
for (var i=0; i < resp.emails.length; i++) {
if (resp.emails[i].type === 'account')
primaryEmail = resp.emails[i].value;
if (resp.displayName != null)
name = resp.displayName;
gender = resp.gender;
}
document.getElementById('responseContainer').value = 'Primary email: ' +
primaryEmail + '\n\nFull Response:\n' + JSON.stringify(resp);
ShowAlert("Email: "+primaryEmail+" "+"Name: "+resp.displayName+" "+"Gender: "+gender);
}
</script>
</html>
For more detailed information and guidance, visit this link:
Getting people and profile information