如何使用Facebook就像在Android应用程序按钮?

问题描述:

我用下面的code在facebook.com的一样的功能与我的Andr​​oid应用进行整合。

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

第一:我使用了一种名为FacebookLikeView.html一个HTML文件,我把它放在资产/网络/文件夹,这是我在以前:

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>

然后我用了一个按钮启动的HTML文件在这样的web视图:

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");
        }
    });

但是,没有什么happend,并在日志中我得到了下面当我点击按钮:

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 

那么,我错在这里做或什么是为了喜欢的Andr​​oid应用一个Facebook页面做正确的事?

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 ?

注意我把上面的html code在HTML文件中,并与Chrome和Firefox打开它,但它没有工作,但它的工作当我把它拷贝到下面的链接 w3school HTML样本。

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.

你同下面的示例例如扔...

Go throw with following sample example ...

https://github.com/crowjdh/android-facebook-like-按钮集成

尝试像按钮Facebook的本土

Try native facebook like button

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

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