1

I am using the following code to integrate the LIKE functionality in facebook.com with my Android app.

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:

<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:

   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 ?

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.

4

2 回答 2

1

使用以下示例示例进行抛出...

https://github.com/crowjdh/android-facebook-like-button-integration

试试原生的 facebook like 按钮

https://developers.facebook.com/docs/android/like-button

参考 https://developers.facebook.com/docs/reference/android/current/class/LikeView

于 2013-04-29T05:56:04.433 回答
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

于 2014-04-19T12:29:18.597 回答