How to implement facebook comment plugin in Android

匿名 (未验证) 提交于 2019-12-03 10:10:24

问题:

How to implement Facebook comments plugin in Android, which allows users to post comments to their wall as shown in the image given below ?

回答1:

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


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