Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
UrlLoader is not working from Gideros Player in Desktop with 201508 version — Gideros Forum

UrlLoader is not working from Gideros Player in Desktop with 201508 version

jdbcjdbc Member
edited September 2015 in General questions
I was trying to integrate parse.com API in some of my games replacing not working Heyzap leaderboard with Facebook authentication. But the point is UrlLoader is not working from Gideros Player running in desktop.

I have tested the same source code in some Gideros Player (older Gideros version) and it works. In desktop I always get an error event. Do you have the same problem with UrlLoader?

Comments

  • UrlLoader does not work for Gideros Player 201509 in desktop.
  • Hello, I tried UrlLoader examples in Studio and they all work, is it possible problem is somewhere else?
  • jdbcjdbc Member
    edited September 2015
    I am using UrlLoader to create anonymous user in parse.com but it works only in Android device.

    I have created a demo "GiderosPlayer" app in parse.com to enable REST request using UrlLoader, so calling Parse.login() should create a new anonymous user. You can try it from Gideros Player running on desktop.
     
    require "json"
     
    social = {} -- Facebook data and empty for anonymous user
     
    local headers = {
    	["X-Parse-Application-Id"] = "DWH32LS3x6T5n5Gu9283ybtxOxoafRlHbXat8A5M",
    	["X-Parse-REST-API-Key"] = "VTpJTp9YMkpBxMI7g2ibUqH3fCyBc1xKLlpNEzKB",
    	["Content-Type"]  = "application/json"
    }
     
    local random = math.random
    local function uuid()
        local template ='xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
        return string.gsub(template, '[xy]', function (c)
            local v = (c == 'x') and random(0, 0xf) or random(8, 0xb)
            return string.format('%x', v)
        end)
    end
    -- Parse login using authData
    function ParseAPI.login()
     
    	print("ParseAPI.login()")
     
    	local url = '<a href="https://api.parse.com/1/users'" rel="nofollow">https://api.parse.com/1/users'</a>
    	local method = UrlLoader.POST
     
    	local data = {}
    	local authData = {}
    	if (social.userid) then -- Facebook user
    		local token = {
    					id = social.userid,
    					access_token = social.accessToken,
    					expiration_date = convertDate(social.expirationDate)
    					}
    		authData.facebook = token
    	else 
    		-- Anonymous user
     
    		local anonymous = {}
    		anonymous.id = uuid()
     
    		authData.anonymous = anonymous
    	end
     
    	data.authData = authData
    	local body = json.encode(data)
     
    	print("body", body)
     
    	local loader = UrlLoader.new(url, method, headers, body)
     
    	local function onComplete(event)
    		print("Parse.login() onComplete", event.data)
     
    		local response = json.decode(event.data)
    		local sessionToken = response.sessionToken
     
    		if (sessionToken) then
    			social.sessionToken = sessionToken
    			dataSaver.saveValue("sessionToken", response.sessionToken)
    		end
     
    		if (social and social.connected and level_manager) then
    			-- First, we get Facebook friends
    			social:getFriends()
     
    			-- Synchronized data with Parse server
    			level_manager:send_data()
    		end
    	end
     
    	local function onError()
    		print("onError")
    	end
     
    	local function onProgress(event)
    		print("onProgress: ")
    	end
     
    	loader:addEventListener(Event.COMPLETE, onComplete)
    	loader:addEventListener(Event.ERROR, onError)
    	loader:addEventListener(Event.PROGRESS, onProgress)
     
    end
  • How can I know the error code inside the onError function?
  • May be it is a problem with parse.com API and desktop.
  • hgy29hgy29 Maintainer
    Accepted Answer
    From your code I can see you use https. It is not supported on desktop by default, you need to install ssl libs. See the issue list on github...

    Likes: jdbc

    +1 -1 (+1 / -0 )Share on Facebook
  • jdbcjdbc Member
    edited September 2015
    From your code I can see you use https. It is not supported on desktop by default, you need to install ssl libs. See the issue list on github...
    Right then.

    Parse.com API needs https protocol. I will test only on Android device.
  • hmm, it might be the https part. I remember @hgy29 once mentioned that you need third party libraries installed for https part to work, but I don't remember which ones now
Sign In or Register to comment.