Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 检查用户是否是Facebook页面的粉丝_Javascript_Facebook_Api_Sdk - Fatal编程技术网

Javascript 检查用户是否是Facebook页面的粉丝

Javascript 检查用户是否是Facebook页面的粉丝,javascript,facebook,api,sdk,Javascript,Facebook,Api,Sdk,登录后,如果用户不是Facebook页面的粉丝,我会尝试返回,但结果总是“未定义”。但如果我将“return”替换为“alert”,则效果会很好 function pageFan() { FB.api({ method: 'pages.isFan', page_id: '175625039138809' }, function(response) { showAlert(response); }); } function showAlert(response)

登录后,如果用户不是Facebook页面的粉丝,我会尝试返回,但结果总是“未定义”。但如果我将“return”替换为“alert”,则效果会很好

function pageFan()
{
    FB.api({ method: 'pages.isFan', page_id: '175625039138809' }, function(response) {
        showAlert(response);
    });
}

function showAlert(response)
{
    if (response == true) {  
        return 'like the Application.';
    } else {
        return "doesn't like the Application.";
    }
}

var like = pageFan();
document.getElementById('debug').innerHTML = like; //return undefined
这个问题已经解决了

相关Javascript:

$(document).ready(function(){
      FB.login(function(response) {
      if (response.session) {

          var user_id = response.session.uid;
          var page_id = "40796308305"; //coca cola
          var fql_query = "SELECT uid FROM page_fan WHERE page_id = "+page_id+"and uid="+user_id;
          var the_query = FB.Data.query(fql_query);

          the_query.wait(function(rows) {

              if (rows.length == 1 && rows[0].uid == user_id) {
                  $("#container_like").show();

                  //here you could also do some ajax and get the content for a "liker" instead of simply showing a hidden div in the page.

              } else {
                  $("#container_notlike").show();
                  //and here you could get the content for a non liker in ajax...
              }
          });


      } else {
        // user is not logged in
      }
    });

这是因为
showart
中的
return
没有返回到
pageFan
功能中。
showarert
函数作为回调传递,这意味着它将在
pageFan
执行之外被调用。我想你需要读书


好的,我明白,但解决方案是什么?解决方案是修改
showart
中的
debug
元素。编辑的answerresponse.session已过时,正确的方式是:response.authResponse
function showAlert(response)
{
    if (response == true) {  
        document.getElementById('debug').innerHTML = 'like the Application.';
    } else {
        document.getElementById('debug').innerHTML = "doesn't like the Application.";
    }
}