question

xigmasuji avatar image
xigmasuji asked

PlayFabAllSDK: DeveloperSecretKey must be set in your local or global settings to call this method.

I am trying to run my azure function locally and and everytime I run it I get the error PlayFabAllSDK: DeveloperSecretKey must be set in your local or global settings to call this method. Despite me adding

PlayFabSettings.staticSettings.TitleId = context.TitleAuthenticationContext.Id;

              PlayFabSettings.staticSettings.DeveloperSecretKey = Environment.GetEnvironmentVariable("PLAYFAB_DEV_SECRET_KEY", EnvironmentVariableTarget.Process);

in the Azure function, I just wanna call PlayFab.PlayFabServerAPI.GetUserDataAsync when I get a request from my game, in the game I use the REST API to call the local URL of the Azure function, though the function calls anytime I make a request to Playfab I receive the error. Please help.

Player Dataapisunity3dCloudScript
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

·
Xiao Zha avatar image
Xiao Zha answered

The code to get DeveloperSecretKey seems correct. Have you followed the documentation: Local debugging for Cloudscript using Azure Functions - PlayFab | Microsoft Learn to set up the DeveloperSecretKey in Azure Function?

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

xigmasuji avatar image xigmasuji commented ·

Okay I added the key and the Title ID in local.settings.json as suggested and created a .json file called playfab.local.settings and added the following line in the file { "LocalApiServer": "http://localhost:7071/api/" } and later also added this file https://github.com/PlayFab/pf-af-devfuncs/blob/main/csharp/ExecuteFunction.cs in the same folder that has the function locally and when I ran it, I was provided with two function URLs Functions:

     ExecuteFunction: [POST] http://localhost:7071/api/CloudScript/ExecuteFunction

     InitializePlayer: [GET,POST] http://localhost:7071/api/InitializePlayer

When I used Execute function I received error

System.Private.CoreLib: Exception while executing function: ExecuteFunction. InitializePlayer: Failed to get Entity Profile: code: 401

[6177-examplefunction.txt][1] and If I use Initialize Player I receive the same

System.Private.CoreLib: Exception while executing function: InitializePlayer. PlayFabAllSDK: DeveloperSecretKey must be set in your local or global settings to call this method.

Please find my code to do this in the attatchment [1]: /storage/attachments/6177-examplefunction.txt

0 Likes 0 ·
Xiao Zha avatar image Xiao Zha xigmasuji commented ·

The “ExecuteFunction” Function is the local implementation of ExecuteFunction API. You should call ExecuteFunction API with the FunctionName to execute the AzureFunction (instead of using the “ExecuteFunction” Function Url with FunctionName to execute the AzureFunction ), then the LocalApiServer will tell the PlayFab SDK to redirect ExecuteFunction API calls to your local implementation.

Also, I replace the “TitleId” in PlayFabId = "TitleID" and PlayFabSettings.staticSettings.TitleId = "TitleID" to my TitleId and PlayFabId, then test your code, it works fine. You may try to hard-code the SecretKey to see if it works.

1 Like 1 ·
xigmasuji avatar image xigmasuji Xiao Zha commented ·

Hey thank you, this was highly helpful.

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.