Skip to content Skip to sidebar Skip to footer

Facebook Like Button In WebView With SDK

I'm trying to implement Facebook Like button which is not part of Android Facebook SDK using WebView. The idea is very simple. I use SDK to log into user account using SSO so user

Solution 1:

I'm not quite sure about FB app access token being valid for using the web api, but let's try something.

First, make sure you're actually using cookies for your WebView instance:

CookieManager.getInstance().setAcceptCookies(true);

I'm not sure whether the facebook redirect page will try to set cookies, so try this and see if it does the trick:

webview.setWebViewClient(new WebViewClient() {  
  @Override  
  public boolean shouldOverrideUrlLoading(WebView view, String url)  
  {  
    view.loadUrl(url);  
    return true;
  }  
});

This will force your WebView to open links within itself, so cookies - if any - won't be lost in case the like page issues a redirect.

If problem still persists you can also try setting cookies manually by executing this before you load the url in your WebView:

// This just initializes the sync manager, do it once
CookieSyncManager.createInstance(this);

CookieManager.getInstance().setCookie("facebook.com", "token="
        + mFacebook.getAccessToken() + "; domain=facebook.com");
CookieSyncManager.getInstance().sync();

Solution 2:

I think this is what you are looking for: https://developers.facebook.com/docs/authentication/server-side/

If I'm reading this correctly, once you implement OAuth, you can use the Graph API to implement the "Like" button you are looking for because you can authenticate the device - not just the user.


Post a Comment for "Facebook Like Button In WebView With SDK"