Android Question Making LIKE and SHARE buttons work with B4A

TheWind777

Active Member
Licensed User
Longtime User
OK. It seems like nobody has ever succeeded getting LIKE and SHARE buttons working.

I haven't yet proven that this is the answer - but I'm quite sure it will work.

First, I created a Facebook Developer's App on:

https://developers.facebook.com

Afterwards, they gave me an App ID and an App Secret.

App ID - 387721248######
App Secret - 7160a1a549b957d99a54632458######

To use the LIKE and SHARE buttons, I think all I'll need is the App ID.

...

The thing that confused me on Facebook's site is it says to, "initialize the Javascript SDK by doing a FB.init(params)"

The secret is found on this page:

https://developers.facebook.com/docs/javascript/quickstart/v2.1

Therefore... you do not download or install any JAR file in the Library or anything like that.

The Facebook SDK is DOWNLOADED ASYNCHRONOUSLY FROM THE SITE as it is needed.

Therefore, the javascript that is embedded on the web page you are loading into the WebView is the secret of making a SHARE and LIKE button work.

Thus, all you have to do is make the WebView able to interpret Javascript, then load the page into the WebView.

That's all.

And, the WebViewExtras2 library should be able to add Javascript interpretation capability to a WebView.

So, in theory, I'm done (even though I haven't actually tried it yet).

The html code of the page that will be loaded should look something like this:

B4X:
<html>
<head>
<title>Title of the document</title>
</head>
<body>

<!-- https://developers.facebook.com/docs/javascript/quickstart/v2.1 -->

<script>
  window.fbAsyncInit = function() {
  FB.init({
  appId  : 387721248######,
  xfbml  : true,
  version  : 'v2.0'
  });
  };

  FB.ui({
  method: 'share_open_graph',
  action_type: 'og.likes',
  action_properties: JSON.stringify({
  object:'https://developers.facebook.com/docs/',
  })
  }, function(response){});

  (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_US/sdk.js";
  fjs.parentNode.insertBefore(js, fjs);
  }(document, 'script', 'facebook-jssdk'));
</script>

<br><br>

<! --- PUT YOUR WEB PAGE'S HTML HERE --->

</body>
</html>

Just change the number of the appId to your number. Save that as an .html file and load it into the WebView after setting it to accept Javascript.

Just look up modifications to those functions to modify the features.

So, you don't even have to log-on to Facebook, or use any sharing libraries. The answer lies with Javascript and an external SDK being loaded into a javascript-enabled WebView.

( Just because something is logically the answer does not mean this is the answer, however. I will post the results after I have gotten it working, which shouldn't take too long. )
 
Last edited:
Top