我正在使用js sdk并获取名称,位置,ID等基本信息。很棒,但我还需要一件事,那就是电子邮件。所以我读了here该电子邮件需要扩展权限。我还使用fb.login阅读here如何请求扩展权限。
在本教程的代码here中,我没有调用fb.login但访问者会被提示登录并授予应用程序权限(如果不是)。怎么做的?注册按钮(稍微修改一下教程)是一个div,它有一个用来设置样式的类。
<div class="fb-login-button" data-show-faces="false" data-width="400" data-max-rows="1">Register</div>
好吧,我检查了“注册”按钮,发现它渲染得很好但我从来没有找到一个onclick或一些线索,如何处理用户点击按钮事件。我的 GUESS 是来自样式的iframe有一个src,事件必须在fb端。
所以回到我的脚本,我想也许fb.login和fb.init一起,我可以在那里添加我的烫发请求,但是没有fb.login?我想也许可以将它放在下面的else分支中,但现在没有任何东西可以使用...减去电子邮件的扩展权限?
window.fbAsyncInit = function ()
{
FB.init({...removed for concise....});
//If user authorizes using fb account info:
FB.Event.subscribe('auth.authResponseChange', function (response)
{
if (response.status === 'connected')
{
...removed for concise code...
}
else if (response.status === 'not_authorized')
{
// the user is logged in to Facebook,
// but has not authenticated your app
}
else
{
// the user isn't logged in to Facebook.
//**HERE IS WHERE I WOULD HAVE THOUGHT TO PUT FB.Login**
}
});
};
所以躲避我的是这些棋子如何在拼图中融合在一起。我知道我需要扩展权限才能让json包含电子邮件但不知道在哪里制作烫发。请求???
这里的代码是页面中的实际代码,因此您可以看到我的整个sdk实现。
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function ()
{
FB.init({
appId: 12324, // App ID
status: true, // check login status
cookie: true, // enable cookies
xfbml: true // parse XFBML
});
//If user authorizes using fb account info:
FB.Event.subscribe('auth.authResponseChange', function (response)
{
if (response.status === 'connected') {
// the user is logged in and has authenticated your
// app, and response.authResponse supplies
// the user's ID, a valid access token, a signed
// request, and the time the access token
// and signed request each expire
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
// send access token to server so we can fill in fields
var form = document.createElement("form");
form.setAttribute("method", 'post');
form.setAttribute("action", '/mypage');
var field = document.createElement("input");
field.setAttribute("type", "hidden");
field.setAttribute("name", 'accessToken');
field.setAttribute("value", accessToken);
form.appendChild(field);
document.body.appendChild(form);
form.submit();
} else if (response.status === 'not_authorized') {
// the user is logged in to Facebook,
// but has not authenticated your app
} else {
// the user isn't logged in to Facebook.
}
});
};
// Load the SDK Asynchronously
(function (d) {
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) { return; }
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
</script>
答案 0 :(得分:1)
由于您没有使用SDK本身登录,而是登录按钮,您必须通过scope
参数请求权限,在按钮本身设置为data-scope="…"
,请参阅{{3 }}
另一种选择是删除按钮,然后在您自己制作的按钮/链接上点击FB.login
。