我无法从Facebook帐户获取邮件ID和手机号码等

时间:2016-05-18 09:30:08

标签: facebook-javascript-sdk facebook-login

我们正在开发混合移动应用程序,因为我们有登录页面。

我们希望通过社交网络登录,如Facebook和google.we成功登录Facebook,但我们想要获取Facebook帐户详细信息,如用户名,邮件ID,手机号码和地址等。

我正在获取用户名,只剩下我没有得到。请任何人帮助我,我犯了什么错误和必须做什么。我也给了代码也请找到它。



function fblogin() {
	FB.login(function(response) {
		if (response.authResponse) {
			alert("if");
			getUserInfo(); // Get User Information.
		} else {
			console.log('Authorization failed.');
		}
	}, {
		scope : 'email'
	});

}

function getUserInfo() {
	FB.api('/me', {fields: 'name, username, password, email, first_name, middle_name, last_name, gender, hometown, birthday'}, function(response) {
		alert("name=" + response.name);
		alert("username=" + response.username);
		alert("password=" + response.password);
		alert("id=" + response.id);
		alert("email=" + response.email);
		alert("first_name=" + response.first_name);
		alert("middle_name=" + response.middle_name);
		alert("last_name=" + response.last_name);
		alert("gender=" + response.gender);
		alert("hometown=" + response.hometown);
		alert("birthday=" + response.birthday);
	});
	$.mobile.navigate("#dashboardPage");
}

<!DOCTYPE HTML>
<html>
    	<head>
    		<meta charset="UTF-8">
    		<title>LoginSN</title>
    		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">
    		<!--
    			<link rel="shortcut icon" href="images/favicon.png">
    			<link rel="apple-touch-icon" href="images/apple-touch-icon.png"> 
    		-->
    		<link href="jqueryMobile/jquery.mobile-1.4.5.css" rel="stylesheet">
    		<link rel="stylesheet" href="css/main.css">
    		<script>window.$ = window.jQuery = WLJQ;</script>
    		<script src="jqueryMobile/jquery.mobile-1.4.5.js"></script>
			<script>
			  
				window.fbAsyncInit = function() {
					FB.init({
						appId : '1608113949506014',
						xfbml : true,
						version : 'v2.6'
					});
				};

				(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/en_US/sdk.js";
					fjs.parentNode.insertBefore(js, fjs);
				}(document, 'script', 'facebook-jssdk'));
			</script>
		</head>
		
    	<body style="display: none;">
    	
    		<div data-role="page" id="loginPage">
    			<div data-role="content" style="padding: 15px">
    				<h1 id="fb-welcome"></h1>
					<label for="text">User Name:</label><input type="text" name="text" id="unL">
					<label for="text">Password:</label><input type="password" name="text" id="pwdL">
					<a href="#dashboardPage" data-role="button" id="buttonLn">LOGIN</a>
					<a href="#registrationPage" data-role="button" id="buttonRe">REGISRASTION</a>
					<a href="#" data-role="button" id="buttonF" onclick="fblogin()">via Facebook Login</a>
					<a href="#" data-role="button" id="login">via Google Login</a>
					<a href="#" data-role="button" id="buttonT">via Twitter Login</a>
				</div>
    		</div>
    		
    		<div data-role="page" id="registrationPage">
    			<div data-role="content" style="padding: 15px">
    				<label for="text">Name:</label><input type="text" name="text" id="unR">
					<label for="text">DOB:</label><input type="date" name="text" id="pwdR">
					<label for="text">Contact No:</label><input type="number" name="text" id="pwdR">
					<label for="text">Email ID:</label><input type="email" name="text" id="pwdR">
    				<label for="text">User Name:</label><input type="text" name="text" id="unR">
					<label for="text">Password:</label><input type="password" name="text" id="pwdR"> 
					<a href="#loginPage" data-role="button" id="buttonR">Registered</a>
		</div>
    		</div>
    		
    		<div data-role="page" id="dashboardPage">
    			<div data-role="content" style="padding: 15px">
    				
    			</div>
    		</div>
    		
    		<script src="js/initOptions.js"></script>
    		<script src="js/main.js"></script>
    		<script src="js/messages.js"></script>
    		
    	</body>
</html>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

FB.api('/me', {fields: 'name,email,first_name,last_name'}, function(response) {
    ...
});

它被称为“声明字段”,您必须指定要在API调用中获得的字段。

顺便说一下,根本不可能获得电话号码或用户名(只有真实姓名)。

用户表的现有字段:https://developers.facebook.com/docs/graph-api/reference/v2.6/user

现有权限:https://developers.facebook.com/docs/facebook-login/permissions

更多信息:https://developers.facebook.com/docs/apps/changelog