我想要做的就是按照用戶來我的網頁上,執行不同的動作按照Facebook的登錄狀態
- 檢查Facebook狀態。如果已登錄並且已經通過我的應用程序授權,則會重定向到新頁面,即
url.php
。 - 如果沒有記錄,並已經授權,則與
connect facebook
按鈕 - 顯示
index.php
頁面如果不是我的應用授權,則要求他做。還要求記住密碼,以便下次登錄時,應該重定向到頁面url.php
我試過FB.getLoginStatus
。當我下面執行簡單的代碼,它工作正常:
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
} else if (response.status === 'not_authorized') {
// but has not authenticated your app
} else {
// the user isn't logged in to Facebook.
}
});
當我試圖做同樣具有以下實際的代碼就永遠不會成功,一堆試後。 實際上發生了什麼,the content on the page like
按鈕and rest it always get loaded even user is logged in or not.
請給我一些暗示此代碼放置適當的條件:
mycode的:
<?php
session_start();
$appId = '178862';
$appSecret = 'xxxxxxxxxxxxxxxxxxxxxxxx'; // Facebook App Secret
$return_url = 'dev01.dev/FB/facebook-php-sdk/examples/'; //path to script folder
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js">
</script>
<title>ThenWat</title>
<script>
function AjaxResponse()
{
//alert("2");
var mydata;
CallAfterLogin(mydata, function(send) {
});
}
function LodingAnimate() //Show loading Image
{
//alert("animate4");
// $("#LoginButton").hide(); //hide login button once user authorize the application
}
</script>
</head>
<body style="height: 560px">
<?php
if(!isset($_SESSION['logged_in']))
{
?>
<div style="z-index: 1; left: 538px; top: 290px; position: absolute;">
<input class="uibutton confirm large" type="submit" value="Connect with facebook" onclick="AjaxResponse()" >
</div>
<?php
}
?>
<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({
appId: '<?php echo $appId; ?>',
cookie: true,
xfbml: true,
// channelUrl: '<?php echo $return_url; ?>channel.php',
oauth: true});};
(function() {
//alert("1");
var e = document.createElement('script');
e.async = true;
e.src = document.location.protocol +'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);}());
function CallAfterLogin(data,callback){
//alert("CallafterLogin3");
FB.login(function(response) { //---
x: FB.getLoginStatus(function(response) {
{
LodingAnimate();
FB.api('/me?fields=movies,email', function(mydata) {
console.log(mydata);
if(mydata.email == null)
{
alert("You must allow us to access your email id!");
ResetAnimate();
}
else
{
//alert("json-5");
var json = JSON.stringify(mydata.movies.data);
// alert(mydata.movies);
var a = JSON.parse(json);
$.post('movies_db.php',{'myd':a}, function(data)
{
$.ajax({
url:'url.php'
,async: true
,cache: false
,dataType: 'html'
,success: function(data){
$('body').html(data);
}
});
});
}
}); //--
} //if
}); //---
} //main function
</script>
</body>
</html>
當我把AjaxResponse()
在onload事件,然後它不符合x
進入
FB.getLoginStatus(function(response) {
如果我把以前document.getElementById("b1").style.display="none";
它隱藏按鈕