### Initializing PlayFab Client and Async Login Request (Java) Source: https://github.com/playfab/javasdk/blob/master/JavaGettingStarted.md This snippet shows the initial setup in the main method, including setting the mandatory PlayFab Title ID, creating a LoginWithCustomIDRequest object, and initiating the asynchronous login process using PlayFabClientAPI.LoginWithCustomIDAsync. It utilizes Java's FutureTask for managing the async operation. ```Java PlayFabSettings.TitleId = "xxxx"; PlayFabClientModels.LoginWithCustomIDRequest request = new PlayFabClientModels.LoginWithCustomIDRequest(); // ... set request parameters like CustomId and CreateAccount ... FutureTask> loginTask = PlayFabClientAPI.LoginWithCustomIDAsync(request); ``` -------------------------------- ### Handling PlayFab API Call Results (Java) Source: https://github.com/playfab/javasdk/blob/master/JavaGettingStarted.md This snippet illustrates the logic within the OnLoginComplete handler. It shows how to retrieve the result from the completed FutureTask using get() and how to check if the API call was successful (result.Result is not null) or if an error occurred (result.Error is not null), providing branches for handling both outcomes. ```Java // Inside OnLoginComplete(FutureTask> loginTask) PlayFabResult result = loginTask.get(); if (result.Result != null) { // API call was successful // Access result.Result for login info } else if (result.Error != null) { // API call failed // Access result.Error for details // Handle failure reasons } ``` -------------------------------- ### Performing PlayFab LoginWithCustomID API Call in Java Source: https://github.com/playfab/javasdk/blob/master/JavaGettingStarted.md This Java code snippet demonstrates how to initialize the PlayFab SDK with a TitleId, create a LoginWithCustomIDRequest, execute the API call asynchronously using FutureTask, and process the result in a separate handler function. It includes basic error handling and reporting. Dependencies include the PlayFab Java SDK and standard Java concurrency utilities. ```Java import java.util.concurrent.*; import java.util.*; import com.playfab.PlayFabErrors.*; import com.playfab.PlayFabSettings; import com.playfab.PlayFabClientModels; import com.playfab.PlayFabClientAPI; public class GettingStarted { private static boolean _running = true; public static void main(String[] args) { PlayFabSettings.TitleId = "144"; PlayFabClientModels.LoginWithCustomIDRequest request = new PlayFabClientModels.LoginWithCustomIDRequest(); request.CustomId = "GettingStartedGuide"; request.CreateAccount = true; FutureTask> loginTask = PlayFabClientAPI.LoginWithCustomIDAsync(request); loginTask.run(); while (_running) { if (loginTask.isDone()) { // You would probably want a more sophisticated way of tracking pending async API calls in a real game OnLoginComplete(loginTask); } else { // Presumably this would be your main game loop, doing other things try { Thread.sleep(1); } catch(Exception e) { System.out.println("Critical error in the example main loop: " + e); } } } } private static void OnLoginComplete(FutureTask> loginTask) { PlayFabResult result = null; try { result = loginTask.get(); // Wait for the result from the async call } catch(Exception e) { System.out.println("Exception in PlayFab api call: " + e); // Did you assign your PlayFabSettings.TitleId correctly? } if (result != null && result.Result != null) { System.out.println("Congratulations, you made your first successful API call!"); } else if (result != null && result.Error != null) { System.out.println("Something went wrong with your first API call."); System.out.println("Here's some debug information:"); System.out.println(CompileErrorsFromResult(result)); } _running = false; // Because this is just an example, successful login triggers the end of the program } // This is a utility function we haven't put into the core SDK yet. Feel free to use it. private static String CompileErrorsFromResult(PlayFabResult result) { if (result == null || result.Error == null) return null; String errorMessage = ""; if (result.Error.errorMessage != null) errorMessage += result.Error.errorMessage; if (result.Error.errorDetails != null) for (Map.Entry> pair : result.Error.errorDetails.entrySet() ) for (String msg : pair.getValue()) errorMessage += "\n" + pair.getKey() + ": " + msg; return errorMessage; } } ``` -------------------------------- ### Waiting for Asynchronous PlayFab Task Completion (Java) Source: https://github.com/playfab/javasdk/blob/master/JavaGettingStarted.md This code demonstrates a simple loop structure used to wait for the asynchronous login task (loginTask) to complete. It repeatedly checks the isDone() method of the FutureTask and calls the OnLoginComplete handler once the task is finished. ```Java while (running) { if (loginTask.isDone()) { OnLoginComplete(loginTask); } } ``` -------------------------------- ### Configuring Maven Central Repository (Gradle) Source: https://github.com/playfab/javasdk/blob/master/README.md This Gradle snippet adds the Maven Central repository to your project's build.gradle file. This is required for Gradle to locate and download the PlayFab SDK dependency. ```Groovy repositories { mavenCentral() } ``` -------------------------------- ### Adding PlayFab SDK Dependencies (Gradle) Source: https://github.com/playfab/javasdk/blob/master/README.md This Gradle snippet shows how to add PlayFab SDK dependencies to your project's build.gradle file. You can include 'client-sdk', 'server-sdk', or 'combo-sdk' by replacing 'VERSION' with the specific SDK version. ```Groovy dependencies { compile('com.playfab.client-sdk:VERSION') compile('com.playfab.server-sdk:VERSION') compile('com.playfab.combo-sdk:VERSION') } ``` -------------------------------- ### Adding PlayFab SDK Dependency (Maven) Source: https://github.com/playfab/javasdk/blob/master/README.md This XML snippet shows how to add a PlayFab SDK dependency to your Maven project's pom.xml file. Replace 'ARTIFACT' with 'client-sdk', 'server-sdk', or 'combo-sdk' and 'VERSION' with the desired SDK version. ```XML com.playfab ARTIFACT VERSION ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.