Facebook 连接 - Javascript
Facebook connect - Javascript
我正在尝试在我的网站上实施 Facebook 连接以填写输入字段。
尽管我的 Facebook 应用程序询问我是否可以访问电子邮件地址,但我无法获得电子邮件地址或姓氏和名字。
这是我的脚本:
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '######', // App ID
status : true, // check login status
xfbml : true,
cookie : true,
version : 'v2.4' // Version
});
};
function Login()
{
FB.login(function(response) {
if(response.authResponse)
{
getUserInfo();
}else{
console.log('User cancelled login or did not fully authorize.');
}
},{scope: 'public_profile,email'});
}
function getUserInfo()
{
FB.api('/me', function(response) {
document.getElementById("name").value = response.name;
document.getElementById("first_name").value = response.first_name;
document.getElementById("last_name").value = response.last_name;
document.getElementById("email").value = response.email;
FB.api('/me/picture?type=normal', function(response) {
var str ="<br/><b>Pic</b> : <img src='"+response.data.url+"'/>";
str +="<input type='button' value='Logout' onclick='Logout();'/>";
document.getElementById("status").innerHTML=str;
});
});
}
function Logout()
{
FB.logout(function(){document.location.reload();});
}
// 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_EN/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
</script>
有人可以帮我解决这个问题吗?
您应该明确请求您需要的字段:
FB.api('/me?fields=email,...')
请参阅 Using the Graph API 文档中的第 Choosing Fields
章
您也可以在 FB 开发者网站的工具和支持部分使用 Graph API Explorer
尝试您的请求
我正在尝试在我的网站上实施 Facebook 连接以填写输入字段。
尽管我的 Facebook 应用程序询问我是否可以访问电子邮件地址,但我无法获得电子邮件地址或姓氏和名字。
这是我的脚本:
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '######', // App ID
status : true, // check login status
xfbml : true,
cookie : true,
version : 'v2.4' // Version
});
};
function Login()
{
FB.login(function(response) {
if(response.authResponse)
{
getUserInfo();
}else{
console.log('User cancelled login or did not fully authorize.');
}
},{scope: 'public_profile,email'});
}
function getUserInfo()
{
FB.api('/me', function(response) {
document.getElementById("name").value = response.name;
document.getElementById("first_name").value = response.first_name;
document.getElementById("last_name").value = response.last_name;
document.getElementById("email").value = response.email;
FB.api('/me/picture?type=normal', function(response) {
var str ="<br/><b>Pic</b> : <img src='"+response.data.url+"'/>";
str +="<input type='button' value='Logout' onclick='Logout();'/>";
document.getElementById("status").innerHTML=str;
});
});
}
function Logout()
{
FB.logout(function(){document.location.reload();});
}
// 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_EN/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
</script>
有人可以帮我解决这个问题吗?
您应该明确请求您需要的字段:
FB.api('/me?fields=email,...')
请参阅 Using the Graph API 文档中的第 Choosing Fields
章
您也可以在 FB 开发者网站的工具和支持部分使用 Graph API Explorer
尝试您的请求