Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This tutorial describes the steps to request parties from your own services rather than strictly from the client using the RequestPartyService API, giving you more flexibility and control over how you integrate PlayFab Party into your game through a HTTP call.
- It allows you to use your own authentication and authorization mechanisms, or customize the user interface and user experience of party creation and joining.
- It enables you to allocate PlayFab Party strictly on your own terms. By managing the relay network from the service side, you can effectively and reliably set up complex network topologies using your own service or with the help of PlayStream and CloudScript.
- It adds additional defense against abuse by clients by giving you the power to restrict Party creation to services only.
Prerequisites
You need a PlayFab account and have enabled the Party feature.
- Create or sign in to your PlayFab account.
- Enable Party feature via Game Manager from your PlayFab account.
- Download and set up Party SDK. For download links, see Party SDKs.
Note
This tutorial is an alternative process to some of the steps in the more comprehensive Party Quickstart article.
1. Gather your PlayFab title secret key from GameManager
- Sign in to Game Manager.
- Select your Title.
- In the upper-right corner, select the gear icon.
- Select Title settings, then select the Secret Keys tab.
For more information, see Secret Key Management.
2. Obtain a PlayFab entity token
Use the GetEntityToken REST API from your service to exchange the title SecretKey for an Entity Token.
async function getEntityToken(titleId, secretKey) {
try {
// Construct the request URL
const requestUrl =
`https://${titleId}.playfabapi.com/Authentication/GetEntityToken`;
// Create headers with your secret key and content type
const headers = {
'X-SecretKey': secretKey,
'Content-Type': 'application/json', // Add this line
};
// Make the POST request
const response = await fetch(requestUrl, {
method: 'POST',
headers: headers,
});
// Check if the response is successful
if (response.ok) {
const responseBody = await response.json();
console.log(`Entity Token: ${responseBody.data.EntityToken}`);
return responseBody.data.EntityToken;
} else {
console.error(`Error: ${response.status}`);
}
} catch (error) {
console.error(`Exception: ${error.message}`);
}
}
3. Make a POST request
Use the retrieved entity token to make a POST request to the RequestPartyService endpoint with the desired parameters for the party.
async function requestPartyService(titleId, entityToken) {
try {
// Construct the request URL
const requestUrl = `https://${titleId}.playfabapi.com/Party/RequestPartyService`;
// Create headers with the entity token and content type
const headers = {
'X-EntityToken': entityToken,
'Content-Type': 'application/json',
};
// Create the request body with PartyNetworkConfiguration and PreferredRegions
const requestBody = {
NetworkConfiguration: {
MaxUsers: 4,
MaxDevices: 4,
MaxDevicesPerUser: 1,
MaxUsersPerDevice: 1,
},
PreferredRegions: ['WestUs'],
};
// Make the POST request
const response = await fetch(requestUrl, {
method: 'POST',
headers: headers,
body: JSON.stringify(requestBody),
});
// Check if the response is successful
if (response.ok) {
const responseBody = await response.json();
console.log('Party service response:', responseBody);
} else {
console.error(`Error: ${response.status}`);
}
} catch (error) {
console.error(`Exception: ${error.message}`);
}
return null;
}
4. Receive a response
After making the POST request, you'll receive a response containing a network descriptor, which contains all the details necessary for clients connecting to the party server.
{
"code": 200,
"status": "OK",
"data": {
"PartyId": "0543645b-9004-4784-95d7-459cef4a23fa",
"SerializedNetworkDescriptor": "AwBnP28mW2RDBQSQhEeV10Wc70oj+ldlc3RVcwAAAAAAAAAAAAAAAAAAPXqiEpapxSC+Owo1h8qJ5NuEOmtS0oeJqq8h6q5ybZZrbktkbnMtaXIwLTgxZTUtNTI3MWZiZDYtMmMyYS00NGE0LThhNjAtNmZlZjI4ZDAzMjc5Lndlc3R1cy5jbG91ZGFwcC5henVyZS5jb20=",
"InvitationId": "e95366d4-c9ed-4a6e-94f6-215c1d69d467"
}
}
5. Share the network descriptor
Share the network descriptor with any would-be participants of your network. There are a variety of ways to do this. Clients using PlayFab Lobby should follow guidance in Integrate Party with Lobby. You may also manually share the Party network descriptor for quick testing purposes or use your own lobby service and invites based on the needs of your game.
6. Connect to the Party server
Clients can use the network descriptor to connect to the Party server using the native SDKs as usual. If this is your first time connecting to a Party network, see Connect to a Party network section of the Quickstart guide.