我使用以下代码将facebook.com中的LIKE功能与我的Android应用程序集成。
首先:我使用了名为FacebookLikeView.html的html文件,并将其放在“assets / www /”文件夹中,这就是我在其中使用的内容:
<html xmlns:fb="http://ogp.me/ns/fb#">
<body>
<div id="fb-root"></div>
<script>(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_GB/all.js#xfbml=1&appId=My APP ID";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
</body>
<fb:like href="https://www.facebook.com/pages/OmarTalkcom/52242794400" send="true" width="120" show_faces="true" font="arial">
</fb:like>
</html>
然后我用一个按钮在webView中启动html文件,如下所示:
Button like = (Button) findViewById(R.id.button1);
like.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
WebView myWebView = (WebView) findViewById(R.id.webView1);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.loadUrl("file:///android_asset/www/FacebookLikeView.html");
}
});
但是没有任何事情发生在日志中,当我点击按钮时,我得到了以下内容:
04-28 09:33:56.940: D/CONTEXT(31684): nativeDraw called here
04-28 09:33:56.940: D/CONTEXT(31684): PictureSet* draw called here
04-28 09:33:56.940: V/(31684): In ResourceHandle::create newHandle
04-28 09:33:56.990: D/dalvikvm(31684): GC_CONCURRENT freed 103K, 4% free 7195K/7431K, paused 8ms+3ms
04-28 09:33:56.990: D/CONTEXT(31684): nativeDraw called here
04-28 09:33:56.990: D/CONTEXT(31684): PictureSet* draw called here
04-28 09:33:57.080: D/CONTEXT(31684): nativeDraw called here
04-28 09:33:57.080: D/CONTEXT(31684): PictureSet* draw called here
那么我在这里做错了什么,或者为了喜欢Android应用中的Facebook页面做什么是正确的?
注意我将上面的html代码放在html文件中并使用chrome和firefox打开它,但是它没有用,但是当我将它复制到{{3}中的以下链接时它起作用了} html示例。
答案 0 :(得分:1)
请使用以下示例示例...
https://github.com/crowjdh/android-facebook-like-button-integration
尝试使用原生facebook,如按钮
https://developers.facebook.com/docs/android/like-button
参考 https://developers.facebook.com/docs/reference/android/current/class/LikeView
答案 1 :(得分:1)
<html xmlns:fb="http://ogp.me/ns/fb#">
<body>
<div id="fb-root"></div>
<script>(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 ="https://connect.facebook.net/en_US/all.js#xfbml=1&appId=your app id";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
</body>
<fb:like href="https://www.facebook.com/pages/OmarTalkcom/52242794400" send="true" width="120" show_faces="true" font="arial">
</fb:like>
</html>
注意:您必须填写您的Facebook应用ID,我将js.src更改为https://connect.facebook.net/en_US/all.js