我有一种情况,我调用Facebook.showPermissionDialog('offline_access'...),然后我做了一个ajax.post调用。如果之前调用了权限对话框,则ajax.post调用将失败。但是,在未事先调用权限对话框时,它会成功。有人知道这个对话框和ajax.post之间有某种关系吗?
如果您想直接查看问题,请访问我的应用程序http://apps.facebook.com/rails_dev(这是一个FACEBOOK APP,因此您必须获取您的个人资料)。
这是调用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;
?>[
这是调用ajax.post的FBJS代码:
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 :(得分:0)
如果 ajax.requireLogin 参数为 true ,则为had the same problem。由于您已经要求扩展权限,因此可以将其设置为 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;
});