question

Eddy Pladys avatar image
Eddy Pladys asked

Javascript/Facebook Instant Games : Error code 400 : BadRequest - InvalidAPIEndpoint

Hello,

I use PlayFab with Facebook Instant Games and Phaser. FB Instant Games add-on is initialized in Playfab.

Login code works fine, but when I use UpdateUserTitleDisplayName method, I have error message will "null" instead of my titleID in the https request.

I don't understand the problem, because I set the titleID with "PlayFab.settings.titleID" ?

Thanks for your help

Error message :

In index.html

    .....

    <!-- Séquence Facebook -->
    <script src="https://connect.facebook.net/en_US/fbinstant.6.3.js"></script>
    <script src="lib/phaser-facebook-instant-games.js"></script> 
    <script src="https://download.playfab.com/PlayFabClientApi.js"></script>
    <!--<script src="lib/PlayFabClientApi.js"></script>--> 
    <script src="js/singleton.js"></script> 
    <script src="js/bootFB.js"></script> 
    <script src="js/preloaderFB.js"></script> 


    .....

In my javascript code

        ......

	var id = "A7113";
        PlayFab.settings.titleID = id;

        var playerId = FBInstant.player.getID();
        console.log("playerId : " + playerId);

        // get the Player Signature for the current player
        FBInstant.player.getSignedPlayerInfoAsync(playerId).then(
        function (result) 
        {
            var playerSignature = result.getSignature();
            console.log("playerSignature : " + playerSignature);
                         
            PlayFabClientSDK.LoginWithFacebookInstantGamesId(
            {
                FacebookInstantGamesSignature: playerSignature,
                TitleId: id,
                CreateAccount: true
            }, (response, error) => 
                {             
                    if(error)
                    {
                        console.log(error);
                    } 
                    else
                    {
                        // display account details
                        var result = response.data;
                        var status = "Login Successful. <br \\> Welcome Player: " + result.PlayFabId + "<br \\> Your session ticket is: " + result.SessionTicket;
                        console.log(status);

                        var playerName = FBInstant.player.getName();
                        PlayFabClientSDK.UpdateUserTitleDisplayName(
                        {
                            DisplayName: playerName
                        }, (response, error) => 
                            {       
                                if (response) 
                                {          
                                    console.log("PLAYFAB response : " + JSON.stringify(response));     
                                }
                                if (error)
                                {
                                    console.log("PLAYFAB error : " + JSON.stringify(error));     
                                }
                            }
                        );
                  
                        /*var playerAvatar = FBInstant.player.getPhoto();
                        PlayFabClientSDK.UpdateAvatarUrl(
                        {
                            ImageUrl: playerAvatar
                        }, (response, error) => 
                            {       
                                console.log("PLAYFAB response : " + JSON.stringify(response));     
                                }
                                if (error)
                                {
                                    console.log("PLAYFAB error : " + JSON.stringify(error));     
                                }
                          });*/

                    }
                }
            );  
        });


...................

playfaberror.png (62.2 KiB)
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.

Seth Du avatar image Seth Du ♦ commented ·

May I ask are you using the latest version of Javascript SDK? I will try to reproduce this issue. In addtion, it will be appreciated if you can share a sample with us(please hide private information).

0 Likes 0 ·
Eddy Pladys avatar image Eddy Pladys Seth Du ♦ commented ·

I use the direct url of javascript sdk.

    <script src="https://download.playfab.com/PlayFabClientApi.js"></script>

You can download project with minimal code here.

0 Likes 0 ·
Eddy Pladys avatar image
Eddy Pladys answered

The javascript sdk quickstart code works fine for me so, but this is just a simple start point. In my case you can add Phaser+Facebook apis.

But this workaround works fine and I will continue with this :

return PlayFab._internalSettings.ExecuteRequest("https://a7113.playfabapi.com/" + apiURL, request, authKey, authValue, callback, customData, extraHeaders);
10 |1200

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

Seth Du avatar image
Seth Du answered

I cannot reproduce this issue. Can you modify the "PlayFabClientApi.js" file and add log output to troubleshoot?

Add log sentences for “PlayFab._internalSettings.GetServerUrl() + apiURL” in ExecuteRequestWrapper function before it is returned via "PlayFab._internalSettings.ExecuteRequest". Because PlayFab._internalSettings.GetServerUrl() + apiURL should be the endpoint of API call.

Otherwise, you may also consider refer to the latest JS SDK on GitHub: https://github.com/PlayFab/JavaScriptSDK

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.

Eddy Pladys avatar image Eddy Pladys commented ·

- Try to use the latest github SDK but notice no change.

- Added the logs in ExecuteRequestWrapper() :

	console.log("ExecuteRequestWrapper GetServerUrl : " + PlayFab._internalSettings.GetServerUrl());
	console.log("ExecuteRequestWrapper GetServerUrl + apiURL : " + PlayFab._internalSettings.GetServerUrl() + apiURL);

            return PlayFab._internalSettings.ExecuteRequest(PlayFab._internalSettings.GetServerUrl() + apiURL, request, authKey, authValue, callback, customData, extraHeaders);

- This give console ouptut :

- Try to replace PlayFab._internalSettings.GetServerUrl() by direct url "https://a7113.playfabapi.com/"

return PlayFab._internalSettings.ExecuteRequest("https://a7113.playfabapi.com/" + apiURL, request, authKey, authValue, callback, customData, extraHeaders);

- It work, this give console ouptut :

- In the Playfab dashboard, player display name is correctly updated.

It works with the GetServerUrl() replacement, but it is not normal way.

Thanks for your help.

0 Likes 0 ·
playfab2.png (50.1 KiB)
playfab4.png (4.3 KiB)
Seth Du avatar image Seth Du ♦ Eddy Pladys commented ·

According to the code, the below code in "GetServerUrl" function should be returned:

return "https://" + PlayFab.settings.titleId + PlayFab.settings.productionServerUrl;

Meanwhile, "PlayFab.settings.titleId" is something you have defined in your code. I am not expert on JS, but I am guessing the title ID is replaced with null after your assignment when this part of function is called.

0 Likes 0 ·
Eddy Pladys avatar image Eddy Pladys Seth Du ♦ commented ·

Yes, this is strange, when I set the titleID directly in the UpdateUserTitleDisplayName function, the log after set give null.

 UpdateUserTitleDisplayName: function (request, callback, customData, extraHeaders) {
        PlayFab.settings.titleID = "A7113";
        console.log("UpdateUserTitleDisplayName PlayFab.settings.titleId : "+PlayFab.settings.titleId);
        return PlayFab._internalSettings.ExecuteRequestWrapper("/Client/UpdateUserTitleDisplayName", request, "X-Authorization", callback, customData, extraHeaders);
    },

I have seen this post about Phaser integration with Playfab. I don't use this RegisterWithPhaser function, but this is related with deprecated version 2 of Phaser.

But maybe there is a link with the settings problem ?

0 Likes 0 ·
Show more comments

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.