我的代码有什么问题?我已经安装了cordova-plugin-facebook4 并且我还提供了从developers.facebook.com获得的正确APP_ID和APP_NAME。
我是PhoneGap项目的新手。
错误:
1. Uncaught DOMException: Blocked a frame with origin "https://staticxx.facebook.com" from accessing a cross-origin frame.
at <anonymous>:1:16
2. (index):32 Uncaught ReferenceError: facebooConnectPlugin is not defined
at LoginWithFB ((index):32)
at HTMLButtonElement.onclick ((index):23)
代码:
<!DOCTYPE html>
<html>
<head>
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="initial-scale=1, width=device-width, viewport-fit=cover">
<link rel="stylesheet" type="text/css" href="css/index.css">
<title>Hello World</title>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
</head>
<body>
<div class="app">
<h1>Apache Cordova</h1>
<div id="deviceready" class="blink">
<p class="event listening">Connecting to Device</p>
<p class="event received">Device is Ready</p>
<button type="button" onclick="LoginWithFB()" class="btn btn-primary" style="background-color: blue;padding:5%;" >Login With Facebook</button>
</div>
</div>
<script type="text/javascript">
function LoginWithFB()
{
alert('Function Start Here');
facebooConnectPlugin.login(['public_profile','email'],function(result){
alert('You Completed 1st Stage');
alert(JSON.stringify(result));
alert('Now Going To The Next Step');
//Success Login Function
facebooConnectPlugin.api("me?fields=email,name,picture",['public_profile','email'],function(userData){
alert('Sorry You Completed Last Round Too..Now You Could Be Logged IN');
alert(JSON.stringify(userData));
},function(error){
alert('Hurrey You Got Erorr 2');
alert(JSON.stringify(error));
});
//Last Error Function
},function(error){
alert('Hurrey You Got A Error');
alert(JSON.stringify(error));
});
alert('Function End Here');
}
</script>
</body>
</html>
答案 0 :(得分:0)
cordova-plugin-facebook4无法正常工作
使用phonegap-facebook-plugin-https://www.npmjs.com/package/phonegap-facebook-plugin
使用代码安装
cordova plugin add phonegap-facebook-plugin
希望有帮助!