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