苦労して、私は最終的に私が達成しようとしていたものの解決策を見つけました。私は正常に自分のアプリケーションとFacebookの投稿を統合しました。Facebookの投稿はページを更新した後に公開されます:Javascript
ただし、問題は1つのみです。私は、人のログイン後にテキストエリアに投稿したい。しかし、私はウェブサイトのページを更新しない限り、私はその投稿を見ることができませんでした。ここで
は、私が実行しようとしているコードです:。
<div id="fb-root"></div>
<script>
function getUserData() {
FB.api('/me', {fields: 'email, posts'}, function(response) {
document.getElementById('for_analysis').innerHTML = 'Hello ' + response.posts.data[0].message;
});
}
window.fbAsyncInit = function() {
//SDK loaded, initialize it
FB.init({
appId : 'MyID',
xfbml : true,
version : 'v2.10'
});
//check user session and refresh it
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
//user is authorized
//document.getElementById('loginBtn').style.display = 'none';
getUserData();
} else {
//user is not authorized
document.getElementById('for_analysis').innerHTML = '';
}
});
};
//load the JavaScript SDK
(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.com/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
//add event listener to login button
document.getElementById('loginBtn').addEventListener('click', function() {
//do the login
FB.login(function(response) {
if (response.authResponse) {
//user just authorized your app
//document.getElementById('loginBtn').style.display = 'none';
getUserData();
//document.location.reload(true)
}
}, {scope: 'email,user_posts', return_scopes: true});
}, false);
</script>
<div class="fb-login-button" data-max-rows="2" data-size="large" data-button-type="continue_with" data-show-faces="false" data-auto-logout-link="true" data-use-continue-as="true" data-scope = "email,user_posts"></div>
親切に、私は中の人がログインした後に内容が表示されるように何をする必要があるか知っているよう
私がしようとしましたコマンドwindow.location.reload()
を使用してgetUserData()
を実行した後にページをリロードすると、window.location.reload(true)
、 document.location.reload()
、およびdocument.location.reload(true)
も試行されました。
しかし、ページがリフレッシュを停止しなかったので、リロード部分を無視しました。
もしあれば、より良い解決策を提案してください。
を、(location.reload'と '(クリックイベントハンドラ内));'あなたが言うように、それはページを再ロードし続けるべきではありません。 – Archer
@Archer申し訳ありませんが、私はあなたの意見を持っていませんでした。助けてくれますか? –
javascriptでページを自動読み込みする必要はありません... – luschn