question

barraganlouisenbairn avatar image
barraganlouisenbairn asked

KONGREGATE - ReferenceError: "Promise" is not defined

I'm creating a new little project in Google Spreadsheets to get some data from Playfab servers for a game in Kongregate. Playfab provides a Javascript API to work:

https://download.playfab.com/PlayFabClientApi.js

I will use the function

But when I try to run my first test I get the error message:

ReferenceError:"Promise" no está definido.(línea 33, archivo "Código")

After some research I readed that Promise is not supported by GAS (Google Apps Script), but somewhere I readed V8 could use promises... I'm little lost, could you help me a little to make this work?

I have this question in stackoverflow:

https://stackoverflow.com/questions/55788388/playfab-referenceerror-promise-is-not-defined?noredirect=1#comment98248050_55788388

My code in my project:

// Load JavaScript from External Servervar url ="https://download.playfab.com/PlayFabClientApi.js";var javascript =UrlFetchApp.fetch(url).getContentText();var token ="1111111111111111111111111111111111111111111111111111111111111111";var kongID ="1111111";eval(javascript);/* ######################################################################## *//* ######################## MENU FUNCTION ################################# *//* ######################################################################## */function onOpen(){var menu =SpreadsheetApp.getUi().createMenu('PLAYFAB MENU');

  menu.addItem('FirstCallPlayfab','PlayFabAPICall').addToUi();}functionPlayFabAPICall(){PlayFab.settings.titleId ="E3FA";var loginRequest ={// Currently, you need to look up the correct format for this object in the API-docs:// https://api.playfab.com/documentation/Client/method/LoginWithCustomIDTitleId:PlayFab.settings.titleId,AuthTicket: token,CreateAccount:false,KongregateId: kongID,};PlayFabClientSDK.LoginWithKongregate(loginRequest,LoginCallback);}varLoginCallback=function(result, error){if(result !==null){Logger.log("Congratulations, you made your first successful API call!");}elseif(error !==null){Logger.log("Something went wrong with your first API call.\n"+"Here's some debug information:\n"+PlayFab.GenerateErrorReport(error));}}

The function LoginWithKongregate in the API file:

LoginWithKongregate:function(request, callback, customData, extraHeaders){
    request.TitleId=PlayFab.settings.titleId ?PlayFab.settings.titleId : request.TitleId;if(!request.TitleId)throwPlayFab._internalSettings.errorTitleId;// PlayFab._internalSettings.authenticationContext can be modified by other asynchronous login attempts// Deep-copy the authenticationContext here to safely update itvar authenticationContext = JSON.parse(JSON.stringify(PlayFab._internalSettings.authenticationContext));var overloadCallback =function(result, error){if(result !=null){if(result.data.SessionTicket!=null){PlayFab._internalSettings.sessionTicket = result.data.SessionTicket;}if(result.data.EntityToken!=null){PlayFab._internalSettings.entityToken = result.data.EntityToken.EntityToken;}// Apply the updates for the AuthenticationContext returned to the client
            authenticationContext =PlayFab._internalSettings.UpdateAuthenticationContext(authenticationContext, result);PlayFab.ClientApi._MultiStepClientLogin(result.data.SettingsForUser.NeedsAttribution);}if(callback !=null&&typeof(callback)==="function")
            callback(result, error);};
apis
10 |1200

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

barraganlouisenbairn avatar image
barraganlouisenbairn answered

Finally The stackoverflow user Tanaike helped me to find a solution: execute the javascript in local client browser, not in the server. That worked well. You can see his solution in stackoverflow. (you have the link in my question). Have a Nice day Marcus, thanks for helping me.

10 |1200

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

Marcus Nixon avatar image
Marcus Nixon answered

Hi,

If Google Apps Script does not support using JavaScript promises, you could try using an alternative to promises like JavaScript's async/await functionality.

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.

barraganlouisenbairn avatar image barraganlouisenbairn commented ·

But how? Must I download and edit the API .js file?

0 Likes 0 ·
Marcus Nixon avatar image
Marcus Nixon answered

Downloading the API .js file and adding to it is one way. However, you would no longer be referencing the PlayFab API file from its source and therefore could potentially find yourself using an old version at some point. You could also try researching how to extend the class or override the method in JavaScript. Of course, neither one of those implementations are supported so you may have to find an alternative on the Google Apps Script side.

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.

barraganlouisenbairn avatar image barraganlouisenbairn commented ·

Could you add how to do the extend or the override? I spent 3 hours trying to do it but I cannot accomplish that. Meanwhile I will try to find the other alternative. Thanks in advance.

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.