0
我正在創建Facebook排行榜,但在更新它時遇到一些問題。當我更新facebook分數然後打開排行榜時,它會顯示舊分數。如果我關閉遊戲並再次打開遊戲,它會顯示正確的排行榜。我究竟做錯了什麼?Facebook圖表排行榜不會立即更新
下面的代碼:
function fClassificaFb(event)
if event.phase == "began" then
bpClassificaFb.isVisible = true
end
if event.phase == "moved" then
bpClassificaFb.isVisible = false
end
if event.phase == "ended" then
bpClassificaFb.isVisible = false
fbAggiornaClassifica()
timer.performWithDelay(150, fbVisualizzaClassifica, 1)
end
end
function fbVisualizzaClassifica(event)
local status = network.getConnectionStatus()
if status.isConnected then
facebook.login(appID, fbListener)
else
fbAlert = native.showAlert("Errore di connessione", "Non è stata rilevata alcuna connessione a Internet.", {"Annulla", "Riprova"}, fbReLogin)
end
end
function fbAggiornaClassifica()
local status = network.getConnectionStatus()
if status.isConnected then
facebook.login(appID, fbListenerAggiorna)
else
fbAlertAggiorna = native.showAlert("Errore di connessione", "Non è stata rilevata alcuna connessione a Internet.", {"Annulla", "Riprova"}, fbReLoginAggiorna)
end
end
function fbListener(event)
if "session" == event.type then
if "login" == event.phase then
access_token = event.token
facebook.request(appID.."/scores")
end
elseif "request" == event.type then
local response = json.decode(event.response)
myData.dataFriends = response.data
storyboard.gotoScene("classifica_facebook")
end
end
function fbListenerAggiorna(event)
if "session" == event.type then
if "login" == event.phase then
access_token = event.token
if storyboard.state.punteggio > myTable.highScore then
myTable.highScore = storyboard.state.punteggio
end
loadsave.saveTable(myTable, "myTable.json")
local attachment = {
score = tostring(myTable.highScore)
}
facebook.request("me/scores" , "POST", attachment)
elseif "request" == event.type then
end
end
end