question

eightartsteam avatar image
eightartsteam asked

Playfab not logging when running in android studio but working well in unity

Here is the code that im using

package playfabcheck.brightmoon.com.playfabtest;

import android.net.Uri;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.appindexing.Thing;
import com.google.android.gms.common.api.GoogleApiClient;
import com.playfab.PlayFabClientAPI;
import com.playfab.PlayFabClientModels.*;
import com.playfab.PlayFabErrors;
import com.playfab.PlayFabSettings;
import java.util.List;
import java.util.Map;
import java.util.concurrent.FutureTask;

public class MainActivity extends AppCompatActivity {

/** * ATTENTION: This was auto-generated to implement the App Indexing API. * See https://g.co/AppIndexing/AndroidStudio for more information. */ // private GoogleApiClient client;@Overrideprotected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);


PlayFabSettings.TitleId = "2FB";

login();
//LoginPlayfab();}


public void login() {
LoginWithCustomIDRequest request = new LoginWithCustomIDRequest();
request.CustomId = "asd";
request.CreateAccount = true;

// var request = new LoginWithCustomIDRequest { CustomId = "GettingStartedGuide", CreateAccount = true}; // PlayFabClientAPI.LoginWithCustomID(request, OnLoginSuccess, OnLoginFailure); // There are several approaches on getting unique android device id. // https://stackoverflow.com/questions/2785485/is-there-a-unique-android-device-id //request.AndroidDeviceId = "qwerty";PlayFabErrors.PlayFabResult<LoginResult> response = PlayFabClientAPI.LoginWithCustomID(request);
if (response.Error != null) {
Toast.makeText(this, "error ", Toast.LENGTH_LONG).show();

Log.d("Foo PlayFab App", CompileErrorsFromResult(response.Error));
//return false;} else {

Toast.makeText(this, "Success ", Toast.LENGTH_LONG).show();

}
// return true;}

private String CompileErrorsFromResult(PlayFabErrors.PlayFabError error) {
if (error == null)
return null;

String errorMessage = "";
if (error.errorMessage != null)
errorMessage += error.errorMessage;
if (error.errorDetails != null)
for (Map.Entry<String, List<String>> pair : error.errorDetails.entrySet())
for (String msg : pair.getValue())
errorMessage += "\n" + pair.getKey() + ": " + msg;
Toast.makeText(this, errorMessage, Toast.LENGTH_LONG).show();

return errorMessage;
}


public void LoginPlayfab() {
LoginWithCustomIDRequest request = new LoginWithCustomIDRequest();
request.CustomId = "ahmadabad";
request.CreateAccount = true;

FutureTask<PlayFabErrors.PlayFabResult<LoginResult>> 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 gameOnLoginComplete(loginTask);
}

// Presumably this would be your main game loop, doing other thingstry {
Thread.sleep(1);
} catch (Exception e) {
System.out.println("Critical error in the example main loop: " + e);
}
}

}

private static boolean _running = true;

private static void OnLoginComplete(FutureTask<PlayFabErrors.PlayFabResult<LoginResult>> loginTask) {
PlayFabErrors.PlayFabResult<LoginResult> 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 <RT> String CompileErrorsFromResult(PlayFabErrors.PlayFabResult<RT> 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<String, List<String>> pair : result.Error.errorDetails.entrySet())
for (String msg : pair.getValue())
errorMessage += "\n" + pair.getKey() + ": " + msg;
return errorMessage;
}







}
Player Datadata
10 |1200

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

1 Answer

·
brendan avatar image
brendan answered

Can you clarify the question? PlayFab is a backend service, with a wide range of features, but we do not log anything in your client code - that's entirely up to you.

If you're having trouble with an API call you're making to PlayFab, can you clarify what the API call is, what parameters you're passing in, and what the results are you're getting back?

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

eightartsteam avatar image eightartsteam commented ·
public void login() {
                   
PlayFabSettings.TitleId = "2FB";
LoginWithCustomIDRequest request = new LoginWithCustomIDRequest();
request.CustomId = "asd";
request.CreateAccount = true;

PlayFabErrors.PlayFabResult<LoginResult> response = PlayFabClientAPI.LoginWithCustomID(request);
if (response.Error != null) {
Toast.makeText(this, "error ", Toast.LENGTH_LONG).show();

Log.d("Foo PlayFab App", CompileErrorsFromResult(response.Error));

} else {

Toast.makeText(this, "Success ", Toast.LENGTH_LONG).show();

}

}

This is the code im using to connect players to play fab, Seems every thing is fine with coding, no errors also.

On running the apk Throwing error Toast message. On debugging the code showing error as " Failed to post to server: https//2FB.playfabapi.com/Client/LoginWithCustomID"

0 Likes 0 ·
brendan avatar image brendan eightartsteam commented ·

Is it literally that? The URL you've posted is missing the : after the https. What SDK version are you using, specifically?

0 Likes 0 ·
brendan avatar image brendan eightartsteam commented ·

The error you're seeing is this: https://github.com/PlayFab/JavaSDK/blob/master/AndroidStudioExample/app/src/main/java/com/playfab/internal/PlayFabHTTP.java#L59.

Can you please update that code to log the exception object ("e"), and let us know what it contains?

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.