question

hayamiyu2002 avatar image
hayamiyu2002 asked

How to get the response of LoginWithPlayFab as the callback in Python SDK?

I would like to impliment Python SDK as the function part of our system. QuickStart is fine, but I want to receive success/falilure response with PlayFabClientAPI.LoginWithCustomID from outside of function. How can I get callback or response this function?

I tried to modify sample code like the follow, but NONE anytime.

from playfab import PlayFabClientAPI, PlayFabSettings PlayFabSettings.TitleId = "144" request = { "CustomId": "GettingStartedGuide", "CreateAccount": True } def callback(success, failure): if success: return True else: return False cb = PlayFabClientAPI.LoginWithCustomID(request, callback)

sdks
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.

hayamiyu2002 avatar image hayamiyu2002 commented ·
 from playfab import PlayFabClientAPI, PlayFabSettings
    
 PlayFabSettings.TitleId = "144"
 request = {
      "CustomId": "GettingStartedGuide",
      "CreateAccount": True }
    
 def callback(success, failure):
      if success:
            return True
      else:
            return False
 cb = PlayFabClientAPI.LoginWithCustomID(request, callback)
0 Likes 0 ·
hayamiyu2002 avatar image hayamiyu2002 commented ·

Can I get the response, not only just print function in callback?

0 Likes 0 ·

1 Answer

·
Simon Cui avatar image
Simon Cui answered

You can refer to the REST API Documentation. For example, if you want to get response from LoginWithCustomID method, you can refer to LoginResult. There are several parameters that you can apply to your code. The callback response can be passed to a function like the code shown below:

 def welcomeMessage(arg1, arg2):
     print("Welcome " + arg1)
     print("Check if it is newly created: " + arg2)
 def checkIfNewlyCreated(arg):
     return str(arg)
    
 from playfab import PlayFabClientAPI, PlayFabSettings
 PlayFabSettings.TitleId = "114"
 request = {
     "CustomId": "Getting",
     "CreateAccount": True
 }
    
 def callback(success, failure):
     if success:
         # print("Congratulations, you made your first successful API call!"   
         welcomeMessage(success["PlayFabId"],checkIfNewlyCreated(success["NewlyCreated"]) )
     else:
         print("Something went wrong with your first API call.  :(")
         if failure:
             print("Here's some debug information:")
             print(failure.GenerateErrorReport())
 PlayFabClientAPI.LoginWithCustomID(request, callback)
10 |1200

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

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.