Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
HTTP request to Scoreoid server using url loader. — Gideros Forum

HTTP request to Scoreoid server using url loader.

joelghilljoelghill Member
edited October 2012 in Code snippets
Hey all,

I'm trying to interact with the Scoreoid API using the Girderos UrlLoader class. I'm able to connect with the url, however it does not seem to like the POST data I am trying to send it. Here's my code:
api = "64bcc44904983cef9fba6b7c783e186bba7ffe95" -- required 
gID = "K6ix5F3lA" --game ID (test game setup through Scoreoid
response = "json"
 
function getPlayer(username, password) -- accepts username and password, returns user info
 
	local headers = {
	["Authorization"] = "Basic"
	}
 
	local method = UrlLoader.POST
	local body = "api_key="..api.."&game_id="..gID.."&response="..response.."&username="..username.."&password="..password
	local url = "<a href="http://www.scoreoid.com/api/getPlayer/&quot" rel="nofollow">http://www.scoreoid.com/api/getPlayer/&quot</a>;
 
 
	local loader = UrlLoader.new(url, method, headers, body)
 
	local function onComplete(event)
		print(event.data)
	end
 
	local function onError()
		print("error")
		end
 
	local function onProgress(event)
		print("progress: " .. event.bytesLoaded .. " of " .. event.bytesTotal)
	end
 
	loader:addEventListener(Event.COMPLETE, onComplete)
	loader:addEventListener(Event.ERROR, onError)
	loader:addEventListener(Event.PROGRESS, onProgress)
 
end
 
getPlayer("username", "password")
This is what is returned in the console:

"Util/Json.lua is uploading.
scoroid.lua is uploading.
Uploading finished.
progress: 113 of 113
<?xml version="1.0" encoding="UTF-8" ?> < error ><! [CDATA[The API key is broken or the game is not active]]>< / error>"

For some reason the POST data I am sending to the URL is not being read. Does anyone see anything wrong with what I'm doing here? I've double checked that that api and game keys are correct.

Thanks!

Comments

Sign In or Register to comment.