Function 如何在';行动后';Facebook JavaScript函数

Function 如何在';行动后';Facebook JavaScript函数,function,facebook-javascript-sdk,Function,Facebook Javascript Sdk,我可以将下面的操作发布到facebook。我现在想做的是自动将当前页面URL插入MYURL。然后,我可以将此代码放在外部文件中,而不必手动插入url并将其放在每个页面上。我是JavaScript新手(我花了很长时间才学会下面的代码)。我已经搜索到死亡,找不到一个方法来做这件事。我将非常感谢任何帮助 <script type="text/javascript"> function postRead() { FB.api('/me/namespace:action&a

我可以将下面的操作发布到facebook。我现在想做的是自动将当前页面URL插入MYURL。然后,我可以将此代码放在外部文件中,而不必手动插入url并将其放在每个页面上。我是JavaScript新手(我花了很长时间才学会下面的代码)。我已经搜索到死亡,找不到一个方法来做这件事。我将非常感谢任何帮助

    <script type="text/javascript">

function postRead()
    {

FB.api('/me/namespace:action&object=http://MYURL','post',  function(response) {
            if (!response || response.error) {
        FB.login(function(response) {
   if (response.authResponse) {
     console.log('Welcome!  Fetching your information.... ');
     FB.api('/me', function(response) {
       console.log('Good to see you, ' + response.name + '.');
     });

FB.api('/me/namespace:action&object=http://MYURL','post',  function(response) {
            if (!response || response.error) {
                alert('Error occured');
              } else {
                 document.getElementById("postlink").innerHTML="Posted!";

              }
        });

   } else {
     console.log('User cancelled login or did not fully authorize.');
   }
 });
              } else {
                 document.getElementById("postlink").innerHTML="Posted!";

              }
        });
    }   


</script>

函数postRead()
{
api('/me/namespace:action和object)=http://MYURL“,”post“,函数(响应){
如果(!response | | response.error){
FB.登录(功能(响应){
if(response.authResponse){
log('欢迎!获取您的信息…);
FB.api('/me',函数(响应){
log(“很高兴见到你,+response.name+”);
});
api('/me/namespace:action和object)=http://MYURL“,”post“,函数(响应){
如果(!response | | response.error){
警报(“发生错误”);
}否则{
document.getElementById(“postlink”).innerHTML=“Posted!”;
}
});
}否则{
log('用户取消登录或未完全授权');
}
});
}否则{
document.getElementById(“postlink”).innerHTML=“Posted!”;
}
});
}   

多亏了这篇文章->,我才算出来。不幸的是,我不能投赞成票,因为我没有名誉,这是一种耻辱

答案代码是双星,这意味着有勇气道歉

function postRead()
    {
FB.api('/me/namespace:action&object='**+encodeURIComponent(location.href)**,'post', function(response) {
            if (!response || response.error) {
        FB.login(function(response) {
   if (response.authResponse) {
     console.log('Welcome!  Fetching your information.... ');
     FB.api('/me', function(response) {
       console.log('Good to see you, ' + response.name + '.');
     });

FB.api('/me/namespace:action&object='+encodeURIComponent(location.href),'post', function(response) {
            if (!response || response.error) {
                alert('Error occured');
              } else {
                 document.getElementById("postlink").innerHTML="Posted!";

              }
        });

   } else {
     console.log('User cancelled login or did not fully authorize.');
   }
 });
              } else {
                 document.getElementById("postlink").innerHTML="Posted!";

              }
        });
    }
可能重复的