2010-01-12 53 views
1

我有一種情況,我打電話給Facebook.showPermissionDialog('offline_access'...),然後我做了一個ajax.post調用。如果先前調用權限對話框,則ajax.post調用失敗。但是,如果權限對話框之前未被調用,它會成功。有沒有人知道這個對話框和ajax.post之間的關係?Facebook的Ajax.post失敗後調用Facebook.showPermissionDialog

如果您想親自檢查問題,請訪問我的應用程序http://apps.facebook.com/rails_dev(這是一個FACEBOOK應用程序,因此您必須使用您的個人資料)。

下面是調用Facebook.showPermissionDialog()的代碼:

<?php 
    echo $this->jsInit($config); 
    if(!$userNamespace->newGame) { 
$log->debug('NOT new game, calling turnResume()'); 
    echo 'setVarBalance(' . $this->gamePlayerData['funds'] . ');'."\n"; 
    echo 'turnResume();'."\n"; 
    } 
    echo $this->drawTrack($this->routeData, $this->trainData); 
    echo $this->drawCityGoods($this->cityGoodsData); 
    //$link = 'startSetCity()'; //$config->url->absolute->fb->canvas . '/turn/start-set-city'; 
    echo $this->drawCitiesAjax($this->cityDescData); 
$log->debug('view: end start-select-city'); 

    if(!$facebook->api_client->users_hasAppPermission('offline_access', $this->fbUserId)): 
?> 
    var dialog = new Dialog().showMessage('Constant Authorization', 'Rails Across Europe is about to request \'Constant Authorization\' to your account. If you don\'t give us constant authorization, Facebook will eventually cause your game to timeout, thereby losing all game information. By granting this authorization, Facebook will not cause your game to timeout. This is the only reason we need this authorization.'); 
    dialog.onconfirm = function() { 
    Facebook.showPermissionDialog('offline_access', null, false, null); 
    } 
<?php 
    endif; 
?>[ 

這裏的FBJS代碼調用ajax.post:

switch(state) { 
     case START_SET_CITY: 
//new Dialog().showMessage('test', 'START_SET_CITY'); 
//console.time('start_set_city'); 
     ajax.responseType = Ajax.JSON; 
     ajax.ondone = function(data) { 
//console.time('ondone'); 
//new Dialog().showMessage('in ajaxSetCity.ondone'); 
//new Dialog().showMessage('test', 'city=' + dump(data.city, 3) + '::: train=' + dump(data.train, 3)); 
      drawCityAjax(data.city, data.train); 
      setVarBalance(data.funds); 
      ajax.responseType = Ajax.JSON; 
      ajax.post(baseURL + '/turn/start'); 
//console.timeEnd('ondone'); 
     }; 
     ajax.post(baseURL + '/turn/start-set-city', param); // <=== THIS IS THE AJAX CALL THAT FAILS 
     var actionPrompt = document.getElementById('action-prompt'); 
     var innerHtml = '<span><div id="action-text">Build Track: Select a city where track building should begin</div>'+ 
         '<div id="action-end">'+ 
         '<input type="button" value="End Track Building" id="next-phase" onClick="moveTrainAuto();" />'+ 
         '</div></span>'; 
     actionPrompt.setInnerXHTML(innerHtml); 
     var btn = document.getElementById('next-phase'); 
     btn.addEventListener('click', moveTrainAutoEvent); 
     state = TRACK_CITY_START; 
//console.timeEnd('start_set_city'); 
     // get funds balance from backend and call setVarBalance() 
     break; 

回答

0

had the same problem如果ajax.requireLogin參數爲。由於您已經要求擴展權限,因此您可以將其設置爲false。下面的代碼適用於我:

Facebook.showPermissionDialog("publish_stream", function(permissions) { 

    var form_data = form.serialize(); 

    var ajax = new Ajax(); 
    ajax.responseType = Ajax.RAW; 
    ajax.requireLogin = false; 
    ajax.ondone = function(data) { 
     console.log("onerror")    
    }; 
    ajax.onerror = function() {    
     console.log("onerror")    
    }; 

    ajax.post("http://foo.example.com/submit", form_data); 

    return false; 
});