我正在为一个Parse App登录Facebook登录,并添加了登录元素,但现在想要将FB个人资料电子邮件和名称添加到数据库中。但是,我无法这样做。我如何能够插入使用Facebook在应用程序上注册的新用户的用户名和电子邮件?
char buf[100];
if (fgets(buf, sizeof buf, stdin) == NULL) Handle_EOF();
buf[strcspn(buf, "\n")] = '\0'; // lop off potential \n
int n1, n2;
int cnt = sscanf(buf, "%d%n%d%n", &d1, &n1, &d2, &n2);
if (buf[0] == '\0') Handle_NothingWasEntered();
else if (cnt == 1 && buf[n1] == '\0') Handle_OneWasEntered(d1);
else if (cnt == 2 && buf[n1] == ' ' && buf[n2] == '\0') Handle_TwoWereEntered(d1, d2);
else Handle_BadInput(buf);
}
答案 0 :(得分:2)
刚刚找到解决方案。我需要在网址上的FB图表中发出请求:
$scope.loginFacebook = function() {
Parse.FacebookUtils.logIn(null, {
success: function(user) {
if (!user.existed()) {
FB.api('/me?fields=id,name,email,permissions', function (response) {
user.set('username', response.name);
user.set('email', response.email);
user.save();
alert("You're registered and logged with via Facebook!");
//redirect to dashboard
});
} else {
alert("You're logged in with Facebook!");
//redirect to dashboard page
}
},
error: function(user, error) {
alert("User cancelled the Facebook login or did not fully authorize.");
}
});
};
答案 1 :(得分:1)
这对你有用......
[]