我正在建立一个实施Google API的网站。我的登录(几乎)完美运行,除了登录时,页面无限刷新。注销时不会发生相同的问题。这里发生了什么?这是我的代码-
return when {
item.itemId == R.id.menuDelete -> {
deleteCar(carx)
true
}
item.itemId == R.id.menuEdit -> {
updateCar(carx)
true
}
else -> super.onContextItemSelected(item)
}
}
private fun updateCar(carx: Car?) {
val builder = AlertDialog.Builder(applicationContext)
builder.setTitle("Edit Car")
val inflater = LayoutInflater.from(applicationContext)
val view = inflater.inflate(R.layout.edit_car,null)
// .....
}
private fun updateCar(carx: Car?) {
// .....
}
“ logScript.php”是指一个PHP脚本,该脚本仅将用户的凭据作为<!-- Google Sign In -->
<script src="https://apis.google.com/js/platform.js?onload=init" async defer></script>
<!-- Google Client Id -->
<!-- <meta name="google-signin-client_id" content="1039303329820-r15n3v6hhg3242kkn733oon7r0qveujs.apps.googleusercontent.com">-->
<meta name="google-signin-client_id" content="113062543899-d3rcmv5khip6dp625rkmk4gdgqmmr3bv.apps.googleusercontent.com">
<script>
$(function(){ onLoad(); });
var auth2;
function onLoad(){
gapi.load('auth2',function() {
auth2=gapi.auth2.init({
client_id: '113062543899-d3rcmv5khip6dp625rkmk4gdgqmmr3bv.apps.googleusercontent.com',fetch_basic_profile: false,scope: 'email',});
});
}
function onSignIn(googleUser){
//alert("what the fuck");
var profile=googleUser.getBasicProfile();
console.log('ID: ' + profile.getId());
console.log('Full Name: ' + profile.getName());
console.log('Given Name: ' + profile.getGivenName());
console.log('Family Name: ' + profile.getFamilyName());
console.log('Image URL: ' + profile.getImageUrl());
console.log('Email: ' + profile.getEmail());
//alert(profile.getGivenName());
$.ajax({
url: "cp_site/scripts/php/logScript.php",type: "POST",data: {
U3: profile.getEmail(),ofa: profile.getGivenName(),wea: profile.getFamilyName()
},success: function(response){
//alert("uh");
if(response == "Email 404"){
$.ajax({
url:"cp_site/scripts/php/logScript.php",data: {
U3: profile.getEmail(),}
});
}
alert(response);
window.location.reload();
},error: function (xhr,ajaxOptions,thrownError) {
alert(xhr.status +" "+ thrownError+"\nReload the page and try again!");
window.location.reload();
}
});
}
function signOut() {
//alert("hello");
var auth2=gapi.auth2.getauthInstance();
auth2.signOut().then(function () {
var auth2=gapi.auth2.getauthInstance();
auth2.signOut();
auth2.disconnect();
$.ajax({
url: "cp_site/scripts/php/logScript.php",success: function(response){
alert(response);
window.location.reload();
},thrownError) {
// alert(xhr.status);
// alert(thrownError);
}
});
});
}
</script>
变量进行处理和存储,因此我认为这不是导致此问题的原因。我之前已经看过这个问题,但是提供的解决方案不适用于我拥有的代码。如果有人对解决此无限循环有任何答案,那就太好了!谢谢!