无法将响应表单 facebook 传递给另一个函数 [英] Unable to pass a response form facebook to another function

查看:15
本文介绍了无法将响应表单 facebook 传递给另一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您查看此问题,请提前感谢您!我正在从 Facebook 中提取数据.

If you view this question thank you in advance!, I am working on pulling data from Facebook.

我正在尝试从 Facebook 中提取用户名,以便我可以在稍后阶段使用它我已将以下代码嵌入到 FB Root div 中.

I am trying to pull the username from Facebook so i can use it in a later stage I have embedded the following code in the FB Root div.

我知道检索有效!但是我无法将它传递给函数 returndata 我对 javascript 比较陌生,你能帮帮我吗?我什么都试过了

I know the retrieve works! however i am not able to pass it on to the function returndata I am relative new to javascript could you please help me out? i have tried everything

那里有一个警报来检查它是否正在检索数据

There is an alert in there to check if it is retrieving data

<div id="fb-root"></div>
<script type="text/javascript">

     $(document).ready(function()
     {
        var appId = "121070974711874";

        // If logging in as a Facebook canvas application use this URL.
        var redirectUrl = "http://apps.facebook.com/bggressive";

        // If logging in as a website do this. Be sure to add the host to your           application's App Domain list. 
        var redirectUrl = window.location.href;

        // If the user did not grant the app authorization go ahead and tell them that. Stop code execution.
        if (0 <= window.location.href.indexOf ("error_reason"))
        {
             $(document.body).append ("<p>Authorization denied!</p>");
             return;
        }


       // When the Facebook SDK script has finished loading init the
       // SDK and then get the login status of the user. The status is
       // reported in the handler.
       window.fbAsyncInit = function()
       {
           FB.init({
                     appId : appId,
                     status : true,
                     cookie : true,
                     oauth : true
           });
           FB.getLoginStatus (onCheckLoginStatus);
       };

       (function(d)
       {
          var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
          js = d.createElement('script'); js.id = id; js.async = true;
          js.src = "//connect.facebook.net/en_US/all.js";
          d.getElementsByTagName('head')[0].appendChild(js);
       }(document));


       function onCheckLoginStatus (response)
       {
          if (response.status != "connected")
          {
              top.location.href = "https://www.facebook.com/dialog/oauth?client_id=" + appId + "&redirect_uri=" + encodeURIComponent (redirectUrl) + "&scope=user_photos,friends_photos";
          }
          else
          {
              FB.api('/me', function(response) 
              {
                  PASON = response.username
                  alert(response.username)
              });
          }
       }
   });

   function returndata()
   {
      get = PASON
      return get
   };

</script>

推荐答案

我认为您是在无法做到的任何随机点调用函数 returndata().原因是 - 变量 PASON 被异步赋值.因此,您必须以这样一种方式进行编码:在分配值后调用 returndata()

I think you are calling the function returndata() at any random point which you can't do. The reason is- the variable PASON is assigned value asynchronously. So, you have to code in such a way that you call returndata() after the value is assigned!

它不是很清楚你想用函数 returndata() 做什么.但是,我希望你现在的概念很清楚.

Its not quite clear what you are trying to do with the function returndata(). But, I hope your concept is clear now.

这篇关于无法将响应表单 facebook 传递给另一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆