<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Google CE API Login test -- Nokia 3310</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" ></script>
<script type="text/javascript">
(function () {
var po = document.createElement('script');
po.type = 'text/javascript'; po.async = true;
po.src = 'https://plus.google.com/js/client:plusone.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(po, s);
})();
</script>
</head>
<body>
<div id="gConnect">
<button class="g-signin"
data-scope="https://www.googleapis.com/auth/plus.login"
data-requestvisibleactions="http://schemas.google.com/AddActivity"
data-clientId="1002186856663-0f64cmr78u4ll1fjeeie6mhslk87p0jo.apps.googleusercontent.com"
data-accesstype="offline"
data-callback="onSignInCallback"
data-theme="dark"
data-cookiepolicy="single_host_origin">
</button>
</div>
<div id="authOps" style="display:none">
<div id="profile"></div>
<div id="visiblePeople"></div>
<pre id="authResult"></pre>
</div>
</body>
<script type="text/javascript">
var helper = (function() {
var authResult = undefined;
return {
onSignInCallback: function(authResult) {
$('#authResult').html('Auth Result:<br/>');
for (var field in authResult) {
$('#authResult').append(' ' + field + ': ' + authResult[field] + '<br/>');
}
if (authResult['access_token']) {
this.authResult = authResult;
helper.connectServer();
gapi.client.load('plus','v1',this.renderProfile);
} else if (authResult['error']) {
console.log('There was an error: ' + authResult['error']);
$('#authResult').append('Logged out');
$('#authOps').hide('slow');
$('#gConnect').show();
}
console.log('authResult', authResult);
},
renderProfile: function() {
var request = gapi.client.plus.people.get( {'userId' : 'me'} );
request.execute( function(profile) {
$('#profile').empty();
if (profile.error) {
$('#profile').append(profile.error);
return;
}
$('#profile').append(
$('<p><img src=\"' + profile.image.url + '\"></p>'));
$('#profile').append(
$('<p>Hello ' + profile.displayName + '!<br />Tagline: ' +
profile.tagline + '<br />About: ' + profile.aboutMe + '</p>'));
if (profile.cover && profile.coverPhoto) {
$('#profile').append(
$('<p><img src=\"' + profile.cover.coverPhoto.url + '\"></p>'));
}
});
$('#authOps').show('slow');
$('#gConnect').hide();
},
disconnectServer: function() {
// Revoke the server tokens
$.ajax({
type: 'POST',
url: window.location.href + '/disconnect',
async: false,
success: function(result) {
console.log('revoke response: ' + result);
$('#authOps').hide();
$('#profile').empty();
$('#visiblePeople').empty();
$('#authResult').empty();
$('#gConnect').show();
},
error: function(e) {
console.log(e);
}
});
},
connectServer: function() {
console.log(this.authResult.code);
$.ajax({
type: 'POST',
url: window.location.href + '/connect?state=test',
contentType: 'application/octet-stream; charset=utf-8',
success: function(result) {
console.log(result);
helper.people();
},
processData: false,
data: this.authResult.code
});
},
people: function() {
$.ajax({
type: 'GET',
url: window.location.href + '/people',
contentType: 'application/octet-stream; charset=utf-8',
success: function(result) {
helper.appendCircled(result);
},
processData: false
});
},
appendCircled: function(people) {
$('#visiblePeople').empty();
$('#visiblePeople').append('Number of people visible to this app: ' +
people.totalItems + '<br/>');
for (var personIndex in people.items) {
person = people.items[personIndex];
$('#visiblePeople').append('<img src="' + person.image.url + '">');
}
},
};
})();
function onSignInCallback(authResult) {
helper.onSignInCallback(authResult);
}
</script>
</html>
<head>
<title>Google CE API Login test -- Nokia 3310</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" ></script>
<script type="text/javascript">
(function () {
var po = document.createElement('script');
po.type = 'text/javascript'; po.async = true;
po.src = 'https://plus.google.com/js/client:plusone.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(po, s);
})();
</script>
</head>
<body>
<div id="gConnect">
<button class="g-signin"
data-scope="https://www.googleapis.com/auth/plus.login"
data-requestvisibleactions="http://schemas.google.com/AddActivity"
data-clientId="1002186856663-0f64cmr78u4ll1fjeeie6mhslk87p0jo.apps.googleusercontent.com"
data-accesstype="offline"
data-callback="onSignInCallback"
data-theme="dark"
data-cookiepolicy="single_host_origin">
</button>
</div>
<div id="authOps" style="display:none">
<div id="profile"></div>
<div id="visiblePeople"></div>
<pre id="authResult"></pre>
</div>
</body>
<script type="text/javascript">
var helper = (function() {
var authResult = undefined;
return {
onSignInCallback: function(authResult) {
$('#authResult').html('Auth Result:<br/>');
for (var field in authResult) {
$('#authResult').append(' ' + field + ': ' + authResult[field] + '<br/>');
}
if (authResult['access_token']) {
this.authResult = authResult;
helper.connectServer();
gapi.client.load('plus','v1',this.renderProfile);
} else if (authResult['error']) {
console.log('There was an error: ' + authResult['error']);
$('#authResult').append('Logged out');
$('#authOps').hide('slow');
$('#gConnect').show();
}
console.log('authResult', authResult);
},
renderProfile: function() {
var request = gapi.client.plus.people.get( {'userId' : 'me'} );
request.execute( function(profile) {
$('#profile').empty();
if (profile.error) {
$('#profile').append(profile.error);
return;
}
$('#profile').append(
$('<p><img src=\"' + profile.image.url + '\"></p>'));
$('#profile').append(
$('<p>Hello ' + profile.displayName + '!<br />Tagline: ' +
profile.tagline + '<br />About: ' + profile.aboutMe + '</p>'));
if (profile.cover && profile.coverPhoto) {
$('#profile').append(
$('<p><img src=\"' + profile.cover.coverPhoto.url + '\"></p>'));
}
});
$('#authOps').show('slow');
$('#gConnect').hide();
},
disconnectServer: function() {
// Revoke the server tokens
$.ajax({
type: 'POST',
url: window.location.href + '/disconnect',
async: false,
success: function(result) {
console.log('revoke response: ' + result);
$('#authOps').hide();
$('#profile').empty();
$('#visiblePeople').empty();
$('#authResult').empty();
$('#gConnect').show();
},
error: function(e) {
console.log(e);
}
});
},
connectServer: function() {
console.log(this.authResult.code);
$.ajax({
type: 'POST',
url: window.location.href + '/connect?state=test',
contentType: 'application/octet-stream; charset=utf-8',
success: function(result) {
console.log(result);
helper.people();
},
processData: false,
data: this.authResult.code
});
},
people: function() {
$.ajax({
type: 'GET',
url: window.location.href + '/people',
contentType: 'application/octet-stream; charset=utf-8',
success: function(result) {
helper.appendCircled(result);
},
processData: false
});
},
appendCircled: function(people) {
$('#visiblePeople').empty();
$('#visiblePeople').append('Number of people visible to this app: ' +
people.totalItems + '<br/>');
for (var personIndex in people.items) {
person = people.items[personIndex];
$('#visiblePeople').append('<img src="' + person.image.url + '">');
}
},
};
})();
function onSignInCallback(authResult) {
helper.onSignInCallback(authResult);
}
</script>
</html>