Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
About scores on Facebook — Gideros Forum

About scores on Facebook

yaxxaryaxxar Member
edited September 2015 in General questions
Hello my friends, in past days I published Nash n' Go on the Play Store, I will update the game in the next days, the game if you still don t play it, has two modes, normal and crazy, each mode has it s own score, and I want to post on facebook for a leader board of friends from the user, but I want to have a leaderboard per mode, like candy crush on its levels, the question is, how can I do that on gideros? Sorry for my bad english, thanks

Comments

  • ar2rsawseenar2rsawseen Maintainer
    Accepted Answer
    Unfortunately facebook allows only one leaderboard per app.
    You would need to use your own server (http://appcodingeasy.com/Mobile-Backend/Score-REST-API-on-PHP5-and-MySQL) or third party server to do that (like parse)
  • yaxxaryaxxar Member
    edited September 2015
    Thanks @ar2rsawseen I gonna check the link, Is a pain work with facebook :-B

    EDIT: or move to Googleplay services
  • I use Parse Cloud Code and UrlLoader to send Rest request and provide several leaderboards for every level in some of my games.
  • jdbcjdbc Member
    edited September 2015 Accepted Answer
    @jdbc can you send me or show here a tutorial please :-B
    Read this one before to understand Parse Cloud:

    https://parse.com/docs/js/guide#cloud-code

    You have to develop javascript functions in the server side for your game and expose them as Http REST API. Gideros provides UrlLoader to submit Http JSON request to those functions:

    In the client side (Gideros) I define the following function to login to Parse with Facebook user:
    -- Parse login using authData
    function ParseAPI.login()
    	local url = base_url.."/1/users"
    	local method = UrlLoader.POST
     
    	local data = {}
    	local authData = {}
    	local token = {
    					id = social.userid,
    					access_token = social.accessToken,
    					expiration_date = social.expirationDate
    					}
     
    	authData.facebook = token
    	data.authData = authData
    	local body = json.encode(data)
     
    	print("body", body)
     
    	local loader = UrlLoader.new(url, method, headers, body)
     
    	local function onComplete(event)
    		print("onComplete", event.data)
    	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
    where social.userid, social.accesstoken and social.expirationDate are provided from previous Facebook user logged.
  • jdbcjdbc Member
    edited September 2015
    @jdbc thanks a lot I will check
    This is the Parse REST API documentation:
    https://parse.com/docs/rest/guide

    With Gideros and UrlLoader, you can submit http request to this Rest API

    Create persistent objects in parse.com is just use the following Lua functions:
    require "json"
     
    local base_url = '<a href="https://api.parse.com'" rel="nofollow">https://api.parse.com'</a>
    local headers = {
    					["X-Parse-Application-Id"] = "XXXXXXXXXXXX",
    					["X-Parse-REST-API-Key"] = "XXXXXXXXXXXX",
    					["Content-Type"]  = "application/json"
    					}
     
    -- Add session token to headers
    local function addSessionToken()
    	if (headers) then
    		local sessionToken = dataSaver.loadValue("sessionToken") -- stored in Parse.login previously
     
    		if (sessionToken) then
    			headers["X-Parse-Session-Token"] = sessionToken
    		end
    	end
    end
     
    -- Create remote object of the given class name
    function ParseAPI.createObject(className, object)
     
    	print("ParseAPI.createObject", className)
     
    	if (className and object) then
    		local url = base_url.."/1/classes/"..className
    		local method = UrlLoader.POST
     
    		-- Session token added to headers
    		addSessionToken()
     
    		local body = json.encode(object)
     
    		local loader = UrlLoader.new(url, method, headers, body)
     
    		local function onComplete(event)
    			print("createObject() onComplete", event.data)
     
    			local response = json.decode(event.data)
    			local objectId = response.objectId
    			dataSaver.saveValue(className, objectId) -- store objectId on disk
     
    		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)
    	else
    		print("Error: class name or object is nil")
    	end
    end
Sign In or Register to comment.