First of all, I would like to thank you for the time you spend to read my post.
I am trying to add Facebook Javascript SDK to a web page and when user logged in, the user data will be saved into mysql using php.
I almost can kind of figure it out how to insert PHP variable data in MYSQL but as this is first time I'm using Javascript language then I am total new :(
To make the story short what I am really looking forward is that someone kindly show me in a simple webpage following things:
1- Webpage starts and checks if the user had been logged into Facebook and also if the user logged into the app (gave permission to the app to have access to the user basic profile info and Email)
2- If the user is not logged into Facebook user will be redirected to the Facebook login page or if user did not give permission to the App yet, it is asking for the necessary permissions.
3- If the user passed the first two stages(user successfully connected), the page will display the following message "Hello dear $User_Facebook_Name".
$User_Facebook_Name is a PHP Variable passed by Javascript from Facebook Javascript SDK
I would like not to use Submit button to pass the Javascript variables to PHP (The website page doesn't refresh).
I prefer to use Facebook Javascript SDK, PHP, Jquery(Ajax) for this issue.
So far I have the following codes and the page displays the message but using Facebook Javascript SDK like this :
FB.api(uid, function(info) {
$('#welcome').html("Hello dear " + info.name );
index.php
<html>
<head>
<script type="text/javascript" src="js/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="js/myscript.js"></script>
</head>
<body>
<div id="fb-root"></div>
Hello dear <?php> echo "$user_Facebook_Name"; ?>
</body>
</html>
myscript.js
window.fbAsyncInit = function() {
FB.init({
appId : 'App_ID',
xfbml : true,
version : 'v2.1'
});
//Next, find out if the user is logged in
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
// the user is logged in and has authenticated your
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
FB.api(uid, function(info) {
$('#welcome').html("Hello dear " + info.name );
});
} else if (response.status === 'not_authorized') {
// the user is logged into Facebook,
// but has not authenticated your app
var oauth_url = 'https://www.facebook.com/dialog/oauth/';
oauth_url += '?client_id=App_ID'; //Your Client ID
oauth_url += '&redirect_uri=' + 'http://website.com/'; //Send them here if they're not logged in
oauth_url += '&scope=email,user_friends';
window.top.location = oauth_url;
} else {
// the user isn't logged in to Facebook.
} //Response.status
}); // Get login status
}; //FB Async
// Load the JavaScript SDK Asynchronously
(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.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
Any help would be really appreciated and would like to thank you in advance.