如何使用Facebook登录按钮获取用户电子邮件? [英] How Can I Get User Email With Facebook Login Button?
本文介绍了如何使用Facebook登录按钮获取用户电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个Facebook登录按钮.确实我做了,但是我需要获取用户名,电子邮件和其他信息.我该怎么办?
I want to create a Facebook login button. Actually I did, but I need to get username, email and other information. How can I do this?
这是我的代码
<html>
<head></head>
<body>
<div id="fb-root"></div>
<script>
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/tr_TR/sdk.js#xfbml=1&version=v2.4&appId=168750412481****";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<div class="fb-login-button" data-max-rows="1" data-size="large" data-show-faces="false" data-auto-logout-link="true" data-scope="email"></div>
</body>
</html>
如何获取数据范围用户的电子邮件或其他范围属性?
How can I get data-scope user email or other scope properties?
推荐答案
我确实需要完整的代码示例.因为我认为Facebook文档很复杂. (或者对我来说),我找到了一个解决方案互联网.在这里您可以在下面看到;
Accualy i need full code example. Because i think facebook documents are complicated. (Or for me) And I found a solution internet. Here you can see below;
FB登录按钮:
<div class="fb-login-button" data-max-rows="1" data-size="large" data-show-faces="false" data-auto-logout-link="true" data-scope="email,user_hometown,user_birthday,user_education_history,user_website,user_work_history"></div>
FB SDK初始化:
FB Sdk initialize:
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/tr_TR/sdk.js#xfbml=1&version=v2.4&appId=***********";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
获取其他用户信息:
window.fbAsyncInit = function() {
FB.init({
appId : '************', // Set YOUR APP ID
channelUrl : 'http://hayageek.com/examples/oauth/facebook/oauth-javascript/channel.html', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true, // parse XFBML
version : 'v2.4',
oauth : true
});
FB.Event.subscribe('auth.authResponseChange', function(response)
{
if (response.status === 'connected')
{
console.log("<br>Connected to Facebook");
//SUCCESS
FB.api('/me', { locale: 'tr_TR', fields: 'name, email,birthday, hometown,education,gender,website,work' },
function(response) {
console.log(response.email);
console.log(response.name);
console.log(response.gender);
console.log(response.birthday);
console.log(response.hometown);
console.log(response.education);
console.log(response.website);
console.log(response.work);
}
);
}
else if (response.status === 'not_authorized')
{
console.log("Failed to Connect");
//FAILED
} else
{
console.log("Logged Out");
//UNKNOWN ERROR
}
});
};
这篇关于如何使用Facebook登录按钮获取用户电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文