我的团队目前正在大学开展一个软件项目,目前的任务是将我们的桌面javafx应用程序绑定到Facebook。
基本上我在控制器中有一个fxml方法,当用户点击" Share"我的GUI中的按钮。在方法中,我想使用WebView简单地打开我的.html文件:
@FXML
public void shareFacebookClicked() throws Exception{
// Setting up the webview
WebView webView = new WebView();
final WebEngine webEngine = webView.getEngine();
webEngine.setJavaScriptEnabled(true);
// Read the html file and let the web engine load it.
File file = new File(getClass().getClassLoader().getResource("facebook.html").toURI().getPath());
webEngine.load(file.toURI().toURL().toString());
Stage stage = new Stage();
stage.initOwner(this.stage);
stage.setScene(new Scene(webView, 1000, 800));
stage.show();
}
没有任何问题,我的" facebook.html"在Web视图中正确加载和显示文件(好吧,几乎正确)。
实际问题是我经常收到191 Facebook错误,说该链接不属于该应用程序。由于互联网上有大量的帖子和问题(是的,我检查并阅读了所有这些)以下是我已经知道的事情:
这些都没有解决我的问题,因此我放弃了研究答案并决定发表我自己的个人问题。 在我看来,.html文件中肯定存在一些错误和/或我完全误解了它的工作方式。 .html文件:
<html>
<head>
<title> Share on Facebook </title>
<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.5.1.js"></script>
<script src="https://connect.facebook.net/en_US/all.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#shareonfacebook').click(function (e) {
FB.ui({
appId: 'MY_APP_ID',
display: "popup",
method: "feed",
name: "Test",
link:"",
caption:"Test",
description: "Test",
});
});
});
</script>
</head>
<body>
<div id="fb-root"></div>
<button id="shareonfacebook" >Share</button>
<script>
FB.init({
appId : 'MY_APP_ID'
});
</script>
</body>
</html>
部分我从教程网站获得此代码。从理论上说它应该有效。 我想要的只是一个对话框,用户可以使用我们的软件发布他/她完成的锻炼结果。目前打开.html文件时,只需一个简单的按钮即可。这和所有&#34;测试&#34; javascript中的字符串仅用于测试。我只想实现我能在墙上发布的东西。下一步当然是以某种方式动态设置发布文本等。
请告诉我我做错了什么或者我应该如何处理整件事。就像我说的那样,任务很少,因此不应该那么困难,但我已经坐在笔记本电脑前2天没有任何成功。如果需要,我已准备好发布更多代码或提供更多信息。
提前感谢您的帮助!