How to implement Facebook comments plugin in Android, which allows users to post comments to their wall as shown in the image given below ?
            Asked
            
        
        
            Active
            
        
            Viewed 6,529 times
        
    3
            
            
        
        Chris Stillwell
        
- 10,266
 - 10
 - 67
 - 77
 
        Amal Dev S I
        
- 938
 - 13
 - 18
 
- 
                    That plugin is available for web only. – CBroe Sep 15 '15 at 11:26
 - 
                    Can i create that plugin in a html file and load it on webview in android ? am searching for something like that.. @CBroe – Amal Dev S I Sep 15 '15 at 13:49
 - 
                    http://stackoverflow.com/questions/16570094/facebook-social-plugin-on-android please look this post. – Artem Jan 15 '16 at 13:09
 
1 Answers
4
            maybe this is not what you looking for but i found few ideas that you could start rolling from like there is a Graph API Facebook social plugin on android or in a WebView Android unable to implement facebook comment in a webview due to default browser
Edit: Should work if you set proper domain and path that already has comments. Haven't checked how it will if original path doesn't have comments
package com.example.ff;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends Activity {
// changeable public variables 
    public static String APP_KEY = "You're app key";
    public static String BASE_DOMAIN = "http://www.9gag.com";
    public static String PATH_URL = "/tv/p/anNBpr";
    private WebView webView;
    private MainActivity context;
    @SuppressWarnings("deprecation")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        context = this;
        CookieSyncManager.createInstance(this);
        CookieManager cm = CookieManager.getInstance();
        cm.removeAllCookie();
        webView = (WebView) findViewById(R.id.web_login);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setDomStorageEnabled(true);
        webView.loadDataWithBaseURL(BASE_DOMAIN, 
                "<html><head></head><body><div id=\"fb-root\"></div><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_KEY+ "\";fjs.parentNode.insertBefore(js, fjs);}(document, 'script', 'facebook-jssdk'));</script><div class=\"fb-comments\" data-href=\""
        +BASE_DOMAIN+PATH_URL+"\" data-width=\"470\"></div> </body></html>", "text/html", null, null);
        webView.setWebViewClient(new WebViewClientActivity());
    }
    public class WebViewClientActivity extends WebViewClient {
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            System.out.println("onPageStarted: " + url);
        }
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            //view.loadUrl(url);
            return true;
        }
        @Override
        public void onPageFinished(WebView webView, String url) {
            System.out.println("onPageFinished: " + url);
        }
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        return super.onOptionsItemSelected(item);
    }
        Community
        
- 1
 - 1
 
        noobie artist
        
- 60
 - 4
 
- 
                    Thanks @noobie artist . But am not looking for that. I want comment plugin exactly like this http://stackoverflow.com/questions/15584176/failed-to-render-facebook-comments-on-android-webview-via-local-html#autocomment31184887 – Amal Dev S I Sep 15 '15 at 13:54
 - 
                    @AmalDevSI use the same thing as here http://stackoverflow.com/questions/19108610/facebook-comment-box-in-android they are using WebView in android – noobie artist Sep 15 '15 at 15:11
 - 
                    But when i use that facebook.html file, an error occur as shown in below. Uncaught SyntaxError: Unexpected token ILLEGAL in var js, fjs = d.getElementsByTagName(s)[0]; Can u solve this ? @noobie artist – Amal Dev S I Sep 16 '15 at 06:26
 - 
                    
 - 
                    @AmalDevSI What should be pass in `PATH_URL` here ? can you please suggest me. – Jay Rathod Aug 11 '16 at 18:06
 - 
                    Placing the APP_KEY in your android aplication is the worst thing you can do – Tiago Oliveira Oct 01 '16 at 00:51
 - 
                    
 
