[英]How to use Facebook like button in Android application?
I am using the following code to integrate the LIKE functionality in facebook.com with my Android app. 我正在使用以下代码将facebook.com中的LIKE功能与我的Android应用程序集成。
First: I used an html file called FacebookLikeView.html and I placed it in "assets/www/" folder, and this is what I used in it: 首先:我使用了一个名为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>
and then I used a button to launch the html file in a webView like this: 然后使用按钮在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");
}
});
But nothing happend and in the log I got the following when I click the button: 但是什么也没发生,当我单击按钮时,在日志中得到以下信息:
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
So what am I doing wrong here or what is the right thing to do in order to like a facebook page from Android app ? 那么,我在这里做错了什么,或者为了使Android应用程序中的Facebook页面更喜欢,该怎么做?
Note I put the above html code in html file and opened it with chrome and firefox but it didn't work, But it worked when I copied it to the following link in w3school html sample. 注意,我将上面的html代码放在html文件中,并使用chrome和firefox打开了它,但是没有用,但是当我将它复制到w3school html示例中的以下链接时,它起作用了。
Go throw with following sample example ... 使用以下示例示例进行抛出...
https://github.com/crowjdh/android-facebook-like-button-integration https://github.com/crowjdh/android-facebook-like-button-integration
Try native facebook like button 尝试像按钮一样的本机Facebook
https://developers.facebook.com/docs/android/like-button https://developers.facebook.com/docs/android/like-button
Reference https://developers.facebook.com/docs/reference/android/current/class/LikeView 参考https://developers.facebook.com/docs/reference/android/current/class/LikeView
<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>
Note:You have to fill your facebook app id and I changed the js.src to https://connect.facebook.net/en_US/all.js 注意:您必须填写您的Facebook应用ID,然后我将js.src更改为https://connect.facebook.net/en_US/all.js
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.