0

以下のアクションを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>
4

1 に答える 1

0

この投稿のおかげで解決しました-> javascript 'onclick'-command の URL から文字を削除します。残念ながら評判がないので投票できず、残念です。

回答コードは 2 つ星になっています。

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!";

              }
        });
    }
于 2012-08-29T22:33:13.643 に答える