FB not defined and prompts error

2019-09-01 10:04发布

问题:

I am a newbie in writing the facebook apps. I would like to use the fb.ui to post the message in the users wall on an apps. But when I call the following method, it prompts the error the fb not defined. I really need some help. My code is as below.

(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/zh_HK/sdk.js#xfbml=1&appId=<?=$app_id?>&version=v2.0";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
    function postToWall(){
         FB.ui({
         method: 'feed',
         name: name,
         link: link,
         picture: picture,
         caption: caption,
         description: redemption,
         message: message
       },
       function (response) {
         if (response && response.post_id) {
           alert(response.post_id);
         } else {

         }
       });
    }


     postToWall();