Facebook like in android

戏子无情 提交于 2020-01-14 06:15:47

问题


I am using the code shown below for like a url in facebook:

String htmlCodeGoesHere="<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 = \"http://connect.facebook.net/en_US/all.js#xfbml=1& appId="+APP_ID+"\";"+
             " fjs.parentNode.insertBefore(js, fjs);"+
            "}(document, 'script', 'facebook-jssdk'));</script>"+
            "<div class=\"fb-like\" data-href=\" http://www.facebook.com/ToshibaInnovation\" data-send=\"false\" data-width=\"450\" data-show-faces=\"true\">   </div>";
            webviewliketoshiba.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
            webviewliketoshiba.setBackgroundColor(Color.WHITE);


            webviewliketoshiba.setWebChromeClient(new WebChromeClient() {

                @Override
                public boolean onJsAlert(WebView view, String url, String message, final android.webkit.JsResult result) {
                    Log.e("js ", message);
                    return false;
                }
            });

            webviewliketoshiba.loadDataWithBaseURL(null, htmlCodeGoesHere, "text/html", "UTF_8", null);

This is showing like button in a web view. I am using OnTouchListener for web view to take particular actions after like. But click on like button it opens browser window with no contents. And not able to get response for like a page.

Can anyone help me to do like functionality. I need response for like a facebook page. I have a valid facebook session and tocken. by getting positive responce from like a url, i can control my other codes.


回答1:


If you are developing your application on core android part, I would suggest you to use the facebook-android-sdk. See the below link :

https://github.com/facebook/facebook-android-sdk

You can find its tutorial at http://ericosgood.com/prog/facebook-android-sdk-tutorial/

Regards.



来源:https://stackoverflow.com/questions/8454659/facebook-like-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!