Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
How to get values from facebook. — Gideros Forum

How to get values from facebook.

somezombiegmsomezombiegm Member
edited January 2015 in General questions
Hey guys!

I'm a real noob here and I honestly don't know how the facebook events work. I've just implemented ar2rsawseen's plugin and succesfully tested his example (after hours of suffering).

I don't understand the Gideros Documentation. For example on http://docs.giderosmobile.com/reference/plugin/Facebook/graphRequest, it says that if I put "me" as a parameter
facebook:graphRequest("me")
I get the data of the currently logged user. Like id, username, name, gender, etc. But how do I implement that? Do the values get stored on a table? For example, If I want to print my name, would this do?
user = facebook:graphRequest("me")
print("Hello:",user.name)

Comments

  • tkhnomantkhnoman Member
    edited January 2015 Accepted Answer
    Use event handler to handle graph request.
     
    	facebook:addEventListener(Event.REQUEST_COMPLETE, function(e)
    		-- print("request complete:", e.type)
    		-- print( )
    		-- for k,v in pairs(e) do print(k,v) end
     
    		if e.type == "me" then
    			if e.response then
    				local tableGet = Json.Decode(e.response) -- this is from other function, not native API
     
    				if tableGet then
    					-- print(tableGet.id)
    				end
    			end	
    		end	
    	end)
     
    	facebook:addEventListener(Event.REQUEST_ERROR, function(e)
    		print("request error:", e.type, e.error)
    	end)
  • somezombiegmsomezombiegm Member
    edited January 2015
    Thanks a lot @tkhnoman, I added the event to the example and now I have this
    require "facebook"
     
    facebook:addEventListener(Event.LOGIN_COMPLETE, function()
    	--print("login successful")
    	facebook:extendAccessTokenIfNeeded()
    end)
     
    facebook:setAppId("352852401492555");
    facebook:authorize();
     
    local text = TextField.new(nil, "post to wall")
    text:setScale(3)
    text:setPosition(10, 150)
    stage:addChild(text)
    text:addEventListener(Event.TOUCHES_BEGIN, function(e)
    	if text:hitTestPoint(e.touch.x, e.touch.y) and facebook:isSessionValid() then
    		facebook:dialog("feed", {
    			link = "<a href="http://giderosmobile.com"" rel="nofollow">http://giderosmobile.com"</a>, 
    			picture = "<a href="http://www.giderosmobile.com/wp-content/uploads/2012/06/gideros-mobile-small.png"" rel="nofollow">http://www.giderosmobile.com/wp-content/uploads/2012/06/gideros-mobile-small.png"</a>, 
    			name = "GiderosMobile.com", 
    			caption = "Awesome tool", 
    			description = "Check out this awesome product"
    		})
    	end
    end)
     
     
    local text2 = TextField.new(nil, "Make api request")
    text2:setScale(3)
    text2:setPosition(10, 350)
    stage:addChild(text2)
    text2:addEventListener(Event.TOUCHES_BEGIN, function(e)
    	if text2:hitTestPoint(e.touch.x, e.touch.y) and facebook:isSessionValid() then
    		facebook:graphRequest("me")
    	end
    end)
     
    local text3 = TextField.new(nil, "Hello user")
    text3:setScale(3)
    text3:setPosition(10, 450)
    stage:addChild(text3)
     
    facebook:addEventListener(Event.REQUEST_COMPLETE, function(e)
    	-- print(e.response)
     
    	-- print("request complete:", e.type)
    	-- print( )
    	-- for k,v in pairs(e) do print(k,v) end
    	text3:setText("test 1")
    	if e.type == "me" then
    		text3:setText("test 2")
    		if e.response then
    			text3:setText("test 3")
    			local tableGet = Json.Decode(e.response) -- this is from other function, not native API
     
    			if tableGet then
    				text3:setText("Hello".." "..tableGet.name.." aka "..tableGet.username)
    				-- print(tableGet.id)
    			end
    		end	
    	end
    end)
     
    facebook:addEventListener(Event.REQUEST_ERROR, function(e)
    	--print(e.errorDescription)
    end)
    So what I'm testing is to write on the textfield something like: Hello Oscar aka somezombie. But the code doesn't get to that part. text3 only shows "test 1". Any ideas why?
  • tkhnomantkhnoman Member
    edited January 2015
    Oops...
    I totally forgot about this.

    Please us this :
    http://giderosmobile.com/labs/facebook

    The facebook at Gideros standard API might be deprecated. (I'm using 2014.01, so i don't know about the recent one.)

    If you need to create a player : http://docs.giderosmobile.com/deployment.html

    (Also, uncomment -- for k,v in pairs(e) do print(k,v) end to get the table e's content)

    Likes: somezombiegm

    +1 -1 (+1 / -0 )Share on Facebook
  • Thanks I'll try it out and come back to you...
  • @tkhnoman First of all, I forgot to say that I'm testing the Facebook plugin on Eclipse :) . And since I'm testing it there, all the prints don't work there, If I want to print something I have to add it to a textfield. Also I'm testing it on a device and the emulator.

    And when you say
    Please us this :
    http://giderosmobile.com/labs/facebook
    Do you mean the code? I don't see any facebook:graphRequest or any way to obtain the logged users data :(.
  • SinisterSoftSinisterSoft Maintainer
    edited January 2015
    you can get the users, their data, images,etc all with the lab lib
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • tkhnomantkhnoman Member
    edited January 2015
    @somezombiegm

    1. http://giderosmobile.com/labs/facebook
    At here, you need to login to view.
    After that, refresh that page, and download would appear.

    2. Then you need to proceed adding Facebook to your game,
    -see install.html inside it to know how to add it

    3. Facebook is a little different with other plugin, it uses Library.
    https://developers.facebook.com/docs/android/getting-started/

    Also, you need hashkey:
    https://developers.facebook.com/docs/android/getting-started/#release-key-hash

    -!! If the app said hashcheck failure, then simply just copy what in the eclipse log by searching "hash", get the hash value and add it to the Android hashkey. Do not remove the old one. This probably only happen after you wrongly doing the things on developer's device.


    4. Before you deploy the game with eclipse,
    -delete asset folder inside asset Folder
    By doing that, you created a player, which work like the real app (considering plug-in, or bundle if you export)


    +1 -1 (+2 / -0 )Share on Facebook
  • @tkhnoman

    It took me a while but now I have my Gideros player for Android with FB plugin, thanks to this link you gave me: http://docs.giderosmobile.com/deployment.html

    No I can test this code on my device
    facebook:graphRequest("me")
     
    facebook:addEventListener(Event.REQUEST_COMPLETE, function(e)
    	--print(e.response)
    	print("request complete:", e.type)
    	print( )
    	for k,v in pairs(e) do print(k,v) end
    	if e.type == "me" then
    		if e.response then
    			local tableGet = Json.Decode(e.response) -- this is from other function, not native API
     
    			if tableGet then
    				print(tableGet.id)
    			end
    		end	
    	end
    end)
    Which prints on my output:

    request complete: nil

    __target table: 0x623c0a00
    __type requestComplete
    __userdata userdata: 0x623c1640
    response {"id":"580168967","education":[{"school":{"id":"106383376064698","name":"Colegio los Pirineos Don Bosco"}, etc, etc, etc.

    I could print my data, which is nice :-bd I can work with that. However, e.type is always nil. I'm not sure if I understood what you said before; If I download the new Gideros 2014.10, will it support e.type?

    I'm using Gideros 2014.01
    I used this SDK: https://developers.facebook.com/docs/android
    And followed this steps: https://developers.facebook.com/docs/android/getting-started


  • I'm also using 2014.01.

    Probably, the difference here is that i'm using this :
    http://giderosmobile.com/labs/facebook

    The API is a little bit different, but it works better.
  • somezombiegmsomezombiegm Member
    edited January 2015
    @tkhnoman I'm sorry I still don't undertand what do you mean by that... :/
  • In that page, you can see Login to view button at the left.
    Just log in, and go to that page again, it would turn into Download.
    And you would get newer plugin for Android at that
  • somezombiegmsomezombiegm Member
    edited January 2015
    @tkhnoman Instead of Download I see "Upgrade to Get it". Since I have a free licence I can't have it I guess.
  • somezombiegmsomezombiegm Member
    edited January 2015
    Sorry for bothering you so much, but when I comment
    --if e.type == "me" then
    I get an error on
    local tableGet = Json.Decode(e.response)
    main.lua:55: attempt to index global 'Json' (a nil value)
  • tkhnomantkhnoman Member
    edited January 2015
    Hmm.. I wonder about that.
    I though they open up all Labs for all member.
    Let's just mention @ar2rsawseen


    That Json is not native API.
    There are many json parser on lua that you can get online.

    ---
    There are also native json, but i never use that. Probably worth to try :
    require "json"
     
    local tableGet = json.decode(e.response)
    Is this run for you?
  • 1. Ok

    2. I added json.lua and now works fine. Thanks
  • All plugins that were in Labs now available on Github:
    https://github.com/gideros/giderosplugins
    :)

    and yes e.type is only in new facebook plugin version, which uses Facebook SDK 3+, the old one was using second FB sdk, which was deprecated quite a while ago.

    Likes: somezombiegm

    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.