I'm a beginner in Javascript and learning how to create websites. I'm trying to add a google+ sign in feature into my web app but couldn't pass session information through javascript. I have 2 js files - login.js and profile.js. When a user logs in, login.js will run, and load a function from profile.js. I included both scripts in the index.html file but still gets this error: loadProfile is not defined. Been stuck for days and really appreciate some guidance!
Here's my code
index.html
{head}
{script src="https://apis.google.com/js/plusone.js"}{/script}
{script src="https://apis.google.com/js/client:plusone.js"}{/script}
{/head}
{body}
{script type="text/javascript" src="Scripts/profile.js"}{/script}
{script type="text/javascript" src="Scripts/login.js"}{/script}
{input type="button" id="login" value="Login" onclick="login()" /}
{input type="button" id="logout" class="hide" value="Logout" onclick="logout()" /}
{script type="text/javascript" src="Scripts/logout.js"}{/script}
{/body}
login.js
function login() {
var myParams = {
'clientid' : '699XXXXXXX.apps.googleusercontent.com',
'cookiepolicy' : 'single_host_origin',
'callback' : 'loginCallback',
'approvalprompt':'force',
'scope' : 'https://www.googleapis.com/auth/plus.login https://www.googleapis.com /auth/plus.profile.emails.read'
};
gapi.auth.signIn(myParams);
}
function loginCallback(result) {
if(result['status']['signed_in']) {
alert("Login Success");
var obj = gapi.auth.getToken();
loadProfile(); // Calls loadProfile() from profile.js
}
}
profile.js
function loadProfile(){
var request = gapi.client.plus.people.get( {'userId' : 'me'} );
request.execute(loadProfileCallback());
}
function loadProfileCallback(obj) {
profile = obj;
email = obj['emails'].filter(function(v) {
return v.type === 'account';
})[0].value;
displayProfile(profile);
}
>>> subsequently it's just some callback functions