Documentation

Did you find this helpful?

Using Publisher Data

This document describes how to create and use publisher (studio) data, which is data spans more than one title, such as when you have multiple games that need to share common information among your games. This category also include data for players that spans multiple games. PlayFab stores data as key/value pairs (KVPs).

Most of these APIs are server APIs that your program must call from a dedicated server or through a Cloud Script function within the PlayFab service.

You must call the server APIs from a dedicated server or through a Cloud Script function through the PlayFab service. This is by design, as the PlayFab server APIs require that you supply your secret key. We do not recommend using Server API’s from within a game client, if you need to make use of a Server API, use Cloud Script for this type of functionality.

NOTE: Publisher Data values are copied and distributed to potentially hundreds of machines in the PlayFab cluster server. As part of this process, Publisher Data is cached and changes may take upto fifteen minutes to refresh in those caches. Publisher Data is best suited for "global constant/static data", and is not suitable or reliable as "global variables".

Publisher Data

Publisher data is used to store static data for a set of title. Each entry is not bound to any PlayFab entity such as Player (as opposed to User Publisher Data). 

Setting Publisher Data

The following snippet demonstrates how to set Publisher Data using Server API. Note, that Admin API counterpart also exists.

public void ServerSetPublisherData() {
    PlayFabServerAPI.SetPublisherData(new SetPublisherDataRequest() {
            Key = "SomeKey",
            Value = "SomeValue"
        }, 
        result => Debug.Log("Complete setting publisher data"),
        error => {
            Debug.Log("Got error setting publisher data");
            Debug.Log(error.GenerateErrorReport());
        }
    );
}

Getting Publisher Data

The following snippets demonstrates getting Publisher Data from using Client API. Note, that both Server and Admin API counterparts exist.

public void ClientGetPublisherData() {
    PlayFabClientAPI.GetPublisherData(new GetPublisherDataRequest(),
    result => {
        if (result.Data == null || !result.Data.ContainsKey("SomeKey")) Debug.Log("No SomeKey");
        else Debug.Log("SomeKey: " + result.Data["SomeKey"]);
    },
    error => {
        Debug.Log("Got error getting publisher data");
        Debug.Log(error.GenerateErrorReport());
    });
}

User Publisher Data

User publisher data can be used to introduce Publisher Data that is bound to PlayFab user (player). Unlike regular Publisher Data, it is possible for client application to alter User Publisher Data. PlayFab exposes 3 protection levels for User Publisher Data from Client API point-of-view:

Regular User Publisher Data exposes read and write access for client application

  • Set via Client, Server and Admin API
  • Get via Client, Server and Admin API
  • Client API may only set Publisher Data for a player currently logged in

Read-Only User Publisher Data exposes read access for client application

  • Set via Server and Admin API
  • Get via Client, Server and Admin API

Internal User Publisher Data exposes no access for client application and is used to store secret portion of user data.

  • Set via Server and Admin API
  • Get via Server and Admin API

Setting User Publisher Data

The following snippet demonstrates how to set all 3 kinds of Publisher Data using Client and Server API:

// Use client API to set User Publisher Data for current user 
public void ClientSetUserPublisherData() {
    PlayFabClientAPI.UpdateUserPublisherData(new UpdateUserDataRequest() {
         Data  = new Dictionary<string, string>() {
             { "SomeKey", "SomeValue" }
         }
    }, 
    result => Debug.Log("Complete setting Regular User Publisher Data"), 
    error =>
    {
        Debug.Log("Error setting Regular User Publisher Data");
        Debug.Log(error.GenerateErrorReport());
    });
}

// Use server API to set Read-Only User Publisher Data for selected user 
public void ServerSetUserPublisherReadOnlyData() {
    PlayFabServerAPI.UpdateUserPublisherReadOnlyData(new UpdateUserDataRequest() {
         PlayFabId = "< PlayFab Player Id >",
         Data  = new Dictionary<string, string>() {
             { "SomeKey", "SomeValue" }
         }
    }, 
    result => Debug.Log("Complete setting Read-Only User Publisher Data"), 
    error =>
    {
        Debug.Log("Error setting Read-Only User Publisher Data");
        Debug.Log(error.GenerateErrorReport());
    });
}

// Use server API to set Internal User Publisher Data for selected user 
public void ServerSetUserPublisherInternalData() {
    PlayFabServerAPI.UpdateUserPublisherInternalData(new UpdateUserInternalDataRequest() {
         PlayFabId = "< PlayFab Player Id >",
         Data  = new Dictionary<string, string>() {
             { "SomeKey", "SomeValue" }
         }
    }, 
    result => Debug.Log("Complete setting Internal User Publisher Data"), 
    error =>
    {
        Debug.Log("Error setting Internal User Publisher Data");
        Debug.Log(error.GenerateErrorReport());
    });
}

Getting User Publisher Data

The following snippet demonstrates how to set all 3 kinds of Publisher Data using Client and Server API:

// Use client API to get Regular User Publisher Data for selected user 
public void ClientGetUserPublisherData() {
    PlayFabClientAPI.GetUserPublisherData(new GetUserDataRequest() {
        PlayFabId = "<PlayFab Player Id>"
    }, result => {
        if (result.Data == null || !result.Data.ContainsKey("SomeKey")) Debug.Log("No SomeKey");
        else Debug.Log("SomeKey: " + result.Data["SomeKey"]);
    },
    error => {
        Debug.Log("Got error getting Regular Publisher Data:");
        Debug.Log(error.GenerateErrorReport());
    });
}

// Use client API to get Read-Only User Publisher Data for selected user 
public void ClientGetUserPublisherReadOnlyData() {
    PlayFabClientAPI.GetUserPublisherReadOnlyData(new GetUserDataRequest() {
        PlayFabId = "<PlayFab Player Id>"
    }, result => {
        if (result.Data == null || !result.Data.ContainsKey("SomeKey")) Debug.Log("No SomeKey");
        else Debug.Log("SomeKey: " + result.Data["SomeKey"]);
    },
    error => {
        Debug.Log("Got error getting Read-Only Publisher Data:");
        Debug.Log(error.GenerateErrorReport());
    });
}

// Use server API to get Internal User Publisher Data for selected user 
public void ServerGetUserPublisherInternalData() {
    PlayFabServerAPI.GetUserPublisherInternalData(new GetUserDataRequest() {
        PlayFabId = "<PlayFab Player Id>"
    }, result => {
        if (result.Data == null || !result.Data.ContainsKey("SomeKey")) Debug.Log("No SomeKey");
        else Debug.Log("SomeKey: " + result.Data["SomeKey"]);
    },
    error => {
        Debug.Log("Got error getting Internal Publisher Data:");
        Debug.Log(error.GenerateErrorReport());
    });
}

See Also:

Using Title Data

Using Cloud Script



Did you find this helpful?