Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat
Error loading profile pic in fb instant - Gideros Forum

Error loading profile pic in fb instant

sam_msam_m Member
edited September 1 in General questions
I'm trying to load profile pictures of players in fb instant game. But I'm getting this error - "|D|profile_pic: No such file or directory.
stack traceback:
GameManager.lua:475: in function "

This is the code I'm using.
result:getPlayerEntryAsync( function (self,result,entry)
 
                        if entry then
 
                            local c = 220
                            for key,val in pairs(entry.entry) do
                                print(key,val)
                                if key=="player" then
                                    for key2,val2 in pairs(val) do
                                        print(" ",key2,val2)                                 
                                    end
                                    if val.photo then
                                        playerData.photo = val.photo
 
                                        local loader = UrlLoader.new('"'..val.photo..'"')
                                        local function onComplete(event)
                                            local out = io.open("|D|profile_pic.jpg", "wb")
 
                                            if out then
                                                out:write(event.data)
                                                out:close()
 
                                                local b = Bitmap.new(Texture.new("|D|profile_pic"))
                                                b:setAnchorPoint(0.5, 0.5)
                                                stage:addChild(b)
                                                b:setPosition(100,100)
                                            end
                                        end
                                        loader:addEventListener(Event.COMPLETE, onComplete)
                                    end
 
                                end
                            end
 
                        end
                    end)
Thanks.

Comments

  • hgy29hgy29 Maintainer
    I can see at least two issues there: first you enclose the url into double quotes, why do you do that ? second, you are saving the picture as profile_pic.jpg but trying to load it as profile_pic (without extension). It is fine to omit the extension but you must do it when saving too then.
  • The url that I'm getting from getPlayerEntryAsync() is something like this - https://platform-lookaside.fbsbx.com/platform/instantgames/profile_pic.jpg?igid=57576575577
    According to the reference on UrlLoader, the link is in quotes like this -
    local loader = UrlLoader.new("http://example.com/image.png") . Hence my addition of the double quotes. Have I done that wrong?

    As for the extension issue, I've tried all combos - with extensions and without. Nothing is working.
  • talistalis Guru
    edited September 2 Accepted Answer
    Hi sam_m,
    If you are gonna pass some string variable to a function you should directly pass it without putting into string (") quotes hence the parameter type is already string.
    But if you have an integer value like a number and you want to use it and generate a string then you can use it like this:
    local loader = UrlLoader.new('"'..val.number..'some other string here"')
    after this code let's suppose your val.number is 1.
    So the end result will be this string:1some other string here
    Anyway as a result your code must be corrected like below:(Only the double quote part, i didn't check the other parts)
    local loader = UrlLoader.new(val.photo)

    Likes: sam_m

    +1 -1 (+1 / -0 ) Share on Facebook
  • talistalis Guru
    edited September 2
    Here is a little bit more info about the subject. When you want to pass a string parameter to a function you have two ways,
    --1st way
    local result = myFunction( "test" )
    --Second way
    local myString = "test"
    local result = myFunction( myString )

    Likes: MoKaLux, sam_m

    +1 -1 (+2 / -0 ) Share on Facebook
  • @hgy29 & @talis - Thank you so much guys. I still haven't solved the problem but with your help, I'm getting there.

    Likes: MoKaLux

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