如何使用Facebook就像在Android应用程序按钮?(How to use Facebook

2019-10-18 02:35发布

我使用下面的代码在facebook.com的一样的功能与我的Android应用程序集成。

第一:我使用所谓的FacebookLikeView.html一个HTML文件,我把它放在“资产/网络/”文件夹,这是我在它使用:

<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文件中像这样的网页视图:

   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并在日志中我得到了,当我按一下按钮如下:

 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打开它,但它没有工作,但它的工作时,我把它拷贝到下面的链接w3school HTML样品。

Answer 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



Answer 2:

去下面的示例例如扔...

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



文章来源: How to use Facebook like button in Android application?