Search code examples
javascriptjavafacebookfacebook-graph-apifacebook-share

while implementing facebook sharing in web app Error get The parameter app_id is required


I am working in java and jsp building a web application. In my web application i am working on facebook sharing functionality. I have done with the facebook login. But getting problem in sharing

The error is The parameter app_id is required A popup comes with the error message and the url in the popup browser is follow

(https://www.facebook.com/dialog/share?app_id=&display=popup&e2e=......)

My code is In HIML

 <div id="fb-root"></div>
   <script src="//connect.facebook.net/en_US/all.js"></script>

 <button type="button" id="btnfbShare" class="btn sign-btn fr">Share on Facebook</button>

IN js

The facebook sdk initialization code

 window.fbAsyncInit = function() {
                FB.init({
                  appId      : '10761986057291117',
                  xfbml      : true,
                  version    : 'v2.4'
                });
              };

              (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'));

And on share button click

 $("#btnfbShare").click(function(event){
                      alert("in share");
                      FB.ui(
                              {

                               method: 'share',
                               href: 'https://developers.facebook.com/docs/'
                             }, function(response){});

                   });

what can be the problem as i am providing the app id at the time of sdk installation.


Solution

  • Got the solution,

    Need to write again initialization on button click

    $("#btnfbShare").click(function(event){                         
        FB.init({
            appId      : '10761986057291117',
            xfbml      : true,
            version    : 'v2.4'
        });
    
        FB.ui({
            method: 'share',
            href: 'https://developers.facebook.com/docs/'
            }, function(response){});
    });