question

Rosen Craft avatar image
Rosen Craft asked

Why is this API not working, I thought session tickets were provided automatically?

1aaaa.png This succesfuly logs the player in, yet when I try to call "GetUserInventory", it crashes the program and says that the "user must be logged in to do this". I don't understand how to correct this, and the console says that the player logs in! This is being used in conjunction with the Solar2d (formerly known as corona) sdk.

apisPlayer Inventorysupport
1aaaa.png (36.5 KiB)
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Citrus Yan avatar image
Citrus Yan answered

In Solar2D SDK, Sessiontickets are indeed set automatically after a successful login, may I know the code snippet of yours that generates the above issue? I tried with the following code and it worked as expected, hope you find it helpful:

local pfClient  = require("plugin.playfab.client")
local json = pfClient.json
local PlayFabClientApi = pfClient.PlayFabClientApi


PlayFabClientApi.settings.titleId = "e0572"


local function printTable( t )
 
    local printTable_cache = {}
 
    local function sub_printTable( t, indent )
 
        if ( printTable_cache[tostring(t)] ) then
            print( indent .. "*" .. tostring(t) )
        else
            printTable_cache[tostring(t)] = true
            if ( type( t ) == "table" ) then
                for pos,val in pairs( t ) do
                    if ( type(val) == "table" ) then
                        print( indent .. "[" .. pos .. "] => " .. tostring( t ).. " {" )
                        sub_printTable( val, indent .. string.rep( " ", string.len(pos)+8 ) )
                        print( indent .. string.rep( " ", string.len(pos)+6 ) .. "}" )
                    elseif ( type(val) == "string" ) then
                        print( indent .. "[" .. pos .. '] => "' .. val .. '"' )
                    else
                        print( indent .. "[" .. pos .. "] => " .. tostring(val) )
                    end
                end
            else
                print( indent..tostring(t) )
            end
        end
    end
 
    if ( type(t) == "table" ) then
        print( tostring(t) .. " {" )
        sub_printTable( t, "  " )
        print( "}" )
    else
        sub_printTable( t, "  " )
    end
end


local function getUserInventory ()
    local request = {


    }
    PlayFabClientApi.GetUserInventory(request, function(result) print("Inventory items: ") printTable(result.Inventory) end, function(error) print("request failed " .. error.errorMessage) end)
end


local loginRequest = {
    -- https://api.playfab.com/Documentation/Client/method/LoginWithCustomID
    CustomId = "CitrusYanTest1",
    CreateAccount = true
}
PlayFabClientApi.LoginWithCustomID(loginRequest, function(result) print("Login Successful: " .. result.PlayFabId) getUserInventory() end, function(error) print("Login Failed: " .. error.errorMessage) end)


1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Rosen Craft avatar image Rosen Craft commented ·

Please see the new answer I added to this post :D, so you can see the code snippet you requested

0 Likes 0 ·
Rosen Craft avatar image
Rosen Craft answered
-- Your code here
local pfClient = require("plugin.playfab.client")
local PlayFabClientApi = pfClient.PlayFabClientApi
PlayFabClientApi.settings.titleId = "850E0" --850E0 [Real ID]

--local pfServer = require("plugin.playfab.server")
--local PlayFabServerApi = pfServer.PlayFabServerApi

local loginRequest = {
    -- See the API reference for LoginWithCustomID.
    CustomId = "GettingStartedGuide",
    CreateAccount = true 
}



PlayFabClientApi.LoginWithCustomID(loginRequest,
    function(result) print("Congratulations, you made your first successful API call!") end,
    function(error) print("Something went wrong with your first API call.\nHere's some debug information:\n" .. error.errorMessage) end
)


local RequestData = {
   
}

--local VirtualCurrencyRC = 0

PlayFabClientApi.GetUserInventory(RequestData,
     function(result) end
)


10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Rosen Craft avatar image
Rosen Craft answered
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Citrus Yan avatar image Citrus Yan commented ·

Does my code work? And, looking at your code, I believe you should call GetUserInventory after receiving the success callback of LoginWithCustomID,

0 Likes 0 ·
Rosen Craft avatar image
Rosen Craft answered

@Citrus Yan

No your code, unfortunately, doesn't work :(

2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Rosen Craft avatar image Rosen Craft commented ·

I apologize @Citrus Yan your code does indeed work thanks!

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan Rosen Craft commented ·

Glad it helped:)

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Error rendering WebPanel (widgets/consolidation-widget.ftl): org.hibernate.hql.internal.ast.QuerySyntaxException: AvailableConsolidation is not mapped [from AvailableConsolidation up where up.node = :node]