-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathauthSample.html
More file actions
66 lines (60 loc) · 2.4 KB
/
authSample.html
File metadata and controls
66 lines (60 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<!--
Rewrite of Google's authSample.html, using gapi-helper.js
The original can be found at
https://code.google.com/p/google-api-javascript-client/source/browse/samples/authSample.html
To run this sample, replace the clientId and apiKey with your application's access keys.
They can be found at https://code.google.com/apis/console/?api=plus under API Access.
Activate the Google+ service at https://code.google.com/apis/console/ under Services
-->
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<script src="gapi-helper.js"></script>
<script src="https://apis.google.com/js/client.js"></script>
</head>
<body>
<!--Add a button for the user to click to initiate auth sequence -->
<button id="authorize-button" style="visibility: hidden">Authorize</button>
<div id="content"></div>
<p>Retrieves your profile name using the Google Plus API.</p>
<script>
// Replace this clientId and apiKey with your own.
// If you don't know what that means, read the section titled "Setup" at
// https://developers.google.com/api-client-library/javascript/start/start-js
//
// The values below only work when run from jsfiddle:
// http://jsfiddle.net/drskot/LfsDs/
gapi_helper.configure({
clientId: '65532434038.apps.googleusercontent.com',
apiKey: 'AIzaSyBcqK9PMBGCEg1xsw4kghrVR4oUthaA_Do',
scopes: 'https://www.googleapis.com/auth/plus.me', // and/or other services
services: {
plus: 'v1' // and/or other services
}
});
gapi_helper.when('authorized', function () {
var authorizeButton = document.getElementById('authorize-button');
authorizeButton.style.visibility = 'hidden';
});
gapi_helper.when('authFailed', function () {
var authorizeButton = document.getElementById('authorize-button');
authorizeButton.style.visibility = '';
authorizeButton.onclick = gapi_helper.requestAuth;
});
gapi_helper.when('plusLoaded', function () {
var request = gapi.client.plus.people.get({
'userId': 'me'
});
request.execute(function (resp) {
var heading = document.createElement('h4');
var image = document.createElement('img');
image.src = resp.image.url;
heading.appendChild(image);
heading.appendChild(document.createTextNode(resp.displayName));
document.getElementById('content').appendChild(heading);
});
});
</script>
</body>
</html>