我正在使用jsf 2.2。我正在尝试在我的jsf项目中实现fb-Login。当我调用FB.api时,访问被拒绝。为了从FB.api获得响应,我应该如何配置我的项目?这里我附上了我的javascript代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:h="http://java.sun.com/jsf/html"
xmlns:fb="http://www.facebook.com/2008/fbml">
<h:head>
<title>FB Login</title>
</h:head>
<h:body>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'appID',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
// Additional initialization code here
FB.api('/platform', function(response) {
alert(response.company_overview);
});
showMe = function(response) {
if (response.status !== 'connected') {
div.innerHTML = '<em>Not Connected</em>';
} else {
FB.api('/me', function(response) {
var i=0;
for (var key in response) {
i++;
switch(i){
case 1: document.getElementById("frm:id").value=response[key]; break;
case 2: document.getElementById("frm:name").value=response[key]; break;
case 3: document.getElementById("frm:firstName").value=response[key]; break;
case 4: document.getElementById("frm:lastName").value=response[key]; break;
case 5: document.getElementById("frm:link").value=response[key]; break;
case 6: document.getElementById("frm:userName").value=response[key]; break;
case 7: document.getElementById("frm:email").value=response[key]; break;
}
}
});
}
};
FB.getLoginStatus(function(response) {
showMe(response);
FB.Event.subscribe('auth.authResponseChange', showMe);
});
};
// 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>
<div id="fbsignin-button" class="show">
<fb:login-button scope="email"></fb:login-button>
</div>
<h:form id="frm">
<h:panelGrid columns="2">
<h:outputLabel for="id" value="ID : "/>
<h:inputText id="id" value="#{FbLoginBean.id}" />
<h:outputLabel for="name" value="Name : "/>
<h:inputText id="name" value="#{FbLoginBean.name}" />
<h:outputLabel for="firstName" value="First Name : "/>
<h:inputText id="firstName" value="#FbLoginBean.firstName}" />
<h:outputLabel for="lastName" value="Last Name : "/>
<h:inputText id="lastName" value="#{FbLoginBean.lastName}" />
<h:outputLabel for="link" value="Link : "/>
<h:inputText id="link" value="#{FbLoginBean.link}" />
<h:outputLabel for="userName" value="User Name : "/>
<h:inputText id="userName" value="#{FbLoginBean.userName}" />
<h:inputHidden id="email" value="#{FbLoginBean.email}" />
<h:commandButton value="Register"
action="#{FbLoginBean.fbDisplay}" />
</h:panelGrid>
</h:form>
</h:body>
</html>
答案 0 :(得分:1)
关于Uncaught SyntaxError:意外的令牌}
正如我在<h:inputText id="firstName" value="#FbLoginBean.firstName}" />
中看到的那样{
#