FB.login()
只有在点击事件触发时才有效。我希望它能在页面加载时自动触发。我尝试使用 trigger()
方法,但没有成功。我也尝试使用 jQuery('#button').click()
来触发它。
$(function(){
//this is logging so I know the js is loading properly
console.log("script loaded");
$('button').button();
$('#button').click(function(){
FB.login(function(response) {
console.log('FBLOGIN firing');
if(response.status === "connected"){
var uID = response.authResponse.userID;
FB.api('/me', function(response) {
var name = response.name;
if(response.location){
var response = response.location.name;
}else{
alert("The Bringer Network needs your current city to be set in your Facebook 'about' section. Please make it public for our use");
}
});//closes fb.api
}else if(response.status === "not_authorized"){
//authCancelled. redirect
}
},{scope: 'user_location,user_likes'});
});//closes click
jQuery('#button').click();
});