I am using HTML 5 to develop a few things and inserting Facebook JavaScript SDK within the same.
I have developed a Facebook application where I want to:
1) If user is not logged in facebook, it will ask for login, but if the user is logged in and opens the application, it should ask for the persmission automatically rather than the user needing to click the link having FB.LOGIN() again.
There is one Stack Overflow question, How do I get my Facebook application to automatically ask for the required permissions post installation where they do it by using window.top.location = "<?php echo $loginUrl; ?>";, but how can I find this authenication URL within JavaScript?
JavaScript code:
<div id="fb-root"></div>
<script>
// Load the SDK asynchronously
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
// Init the SDK upon load
window.fbAsyncInit = function() {
FB.init({
appId : 'appid', // App ID
channelUrl : '//www.domain.com/channel.html', // Channel file
status : true, // Check login status
cookie : true, // Enable cookies to allow the server to access the session
xfbml : true // Parse XFBML
});
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
document.getElementById('auth-loggedout').style.display = 'none';
document.getElementById('auth-loggedinnotauthenticate').style.display = 'none';
document.getElementById('loginauthenicated').style.display = 'block';
}
else
if (response.status === 'not_authorized') {
window.top.location = "https://www.facebook.com/dialog/oauth?client_id=id&redirect_uri=http://apps.facebook.com/appp/";
}
else {
window.top.location = "https://www.facebook.com/login.php?api_key=id&skip_api_login=1&display=page&cancel_url=http://apps.facebook.com/appp/";
}
});
</script>
Use this: