无法将响应表单Facebook传递给另一个功能 [英] Unable to pass a response form facebook to another function
问题描述
如果您提前感谢您,我正在从Facebook上提取数据。
If you view this question thank you in advance!, I am working on pulling data from Facebook.
我正在尝试从Facebook中提取用户名,所以我可以使用它在稍后阶段我已经嵌入以下代码在FB根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屋!