Skip to content

Commit 382bb55

Browse files
author
Playfab Jenkins Bot
committed
https://api.playfab.com/releaseNotes/#170109
2 parents 1806c15 + ec32aa4 commit 382bb55

File tree

5 files changed

+148
-4
lines changed

5 files changed

+148
-4
lines changed

JavaScriptGettingStarted.md

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
2+
JavaScript Getting Started Guide
3+
----
4+
5+
This guide will help you make your first API call in JavaScript.
6+
7+
JavaScript Project Setup
8+
----
9+
10+
* OS: This guide should work in any OS capable of running a web-browser
11+
* Installation
12+
* You are probably already reading this page on your favorite browser
13+
* New Project Setup
14+
* Create a new folder, with two empty text files:
15+
* PlayFabGettingStarted.html
16+
* PlayFabGettingStarted.js
17+
* PlayFab installation complete
18+
19+
Set up your first API call
20+
----
21+
22+
This guide will provide the minimum steps to make your first PlayFab API call. Confirmation will be visible on the webpage.
23+
24+
In your favorite text-editor, update the contents of PlayFabGettingStarted.html as follows:
25+
```HTML
26+
<!DOCTYPE html>
27+
<html>
28+
<head>
29+
<meta charset="utf-8">
30+
<title>PlayFab JavaScript Unit Tests</title>
31+
<script type="text/javascript" src="https://download.playfab.com/PlayFabClientApi.js"></script>
32+
<script type="text/javascript" src="PlayFabGettingStarted.js"></script>
33+
</head>
34+
<body>
35+
PlayFab Getting Started Guide<br />
36+
TitleID: <input type="text" id="titleId" value="144"><br />
37+
CustomID: <input type="text" id="customId" value="GettingStartedGuide"><br />
38+
<input type="button" value="Call LoginWithCustomID" onclick="DoExampleLoginWithCustomID()"><br />
39+
Result:<br />
40+
<textarea id="resultOutput" cols="60" rows="5"></textarea><br />
41+
</body>
42+
</html>
43+
```
44+
45+
In your favorite text-editor, update the contents of PlayFabGettingStarted.js as follows:
46+
```JavaScript
47+
function DoExampleLoginWithCustomID(){
48+
PlayFab.settings.titleId = document.getElementById("titleId").value;
49+
var loginRequest = {
50+
// Currently, you need to look up the correct format for this object in the API-docs:
51+
// https://api.playfab.com/Documentation/Client/method/LoginWithCustomID
52+
TitleId: PlayFab.settings.titleId,
53+
CustomId: document.getElementById("customId").value,
54+
CreateAccount: true
55+
};
56+
57+
PlayFabClientSDK.LoginWithCustomID(loginRequest, LoginCallback);
58+
}
59+
60+
var LoginCallback = function (result, error) {
61+
if (result !== null) {
62+
document.getElementById("resultOutput").innerHTML = "Congratulations, you made your first successful API call!";
63+
} else if (error !== null) {
64+
document.getElementById("resultOutput").innerHTML =
65+
"Something went wrong with your first API call.\n" +
66+
"Here's some debug information:\n" +
67+
CompileErrorReport(error);
68+
}
69+
}
70+
71+
// This is a utility function we haven't put into the core SDK yet. Feel free to use it.
72+
function CompileErrorReport(error) {
73+
if (error === null)
74+
return "";
75+
var fullErrors = error.errorMessage;
76+
for (var paramName in error.errorDetails)
77+
for (var msgIdx in error.errorDetails[paramName])
78+
fullErrors += "\n" + paramName + ": " + error.errorDetails[paramName][msgIdx];
79+
return fullErrors;
80+
}
81+
```
82+
83+
Finish and Execute
84+
----
85+
86+
* Open PlayFabGettingStarted.html in your favorite browser
87+
* Click the "Call LoginWithCustomID" button
88+
* You should see the following text in the Result section:
89+
```text
90+
Congratulations, you made your first successful API call!
91+
```
92+
93+
* At this point, you can start making other api calls, and building your game
94+
* For a list of all available client API calls, see our documentation:
95+
* https://api.playfab.com/
96+
* Happy coding!
97+
98+
Deconstruct the code
99+
----
100+
101+
This optional last section describes each part of Program.cs in detail.
102+
103+
The HTML file has a few important lines:
104+
```HTML
105+
<script type="text/javascript" src="https://download.playfab.com/PlayFabClientApi.js"></script>
106+
```
107+
108+
This line loads the Client-SDK directly from the PlayFab CDN. Our CDN always hosts the latest version of PlayFabSDK. It may be safer for you to download the files, and use a fixed version: [PlayFab JavaScriptSDK](https://api.playfab.com/sdks/download/javascript)
109+
110+
The other important HTML lines:
111+
```HTML
112+
<script type="text/javascript" src="PlayFabGettingStarted.js"></script>
113+
...
114+
<input type="button" value="Call LoginWithCustomID" onclick="DoExampleLoginWithCustomID()"><br />
115+
```
116+
117+
As you can see above, PlayFabGettingStarted.js contains the DoExampleLoginWithCustomID function. These lines bind our js file to our webpage, and invoke the DoExampleLoginWithCustomID function in that script. Everything else is just GUI.
118+
119+
* Line by line breakdown for PlayFabGettingStarted.js
120+
* PlayFab.settings.titleId = "xxxx";
121+
* Every PlayFab developer creates a title in Game Manager. When you publish your game, you must code that titleId into your game. This lets the client know how to access the correct data within PlayFab. For most users, just consider it a mandatory step that makes PlayFab work.
122+
* var loginRequest = { TitleId: PlayFab.settings.titleId, CustomId: "GettingStartedGuide", CreateAccount: true };
123+
* Most PlayFab API methods require input parameters, and those input parameters are packed into a request object
124+
* Every API method requires a unique request object, with a mix of optional and mandatory parameters
125+
* For LoginWithCustomIDRequest, there is a mandatory parameter of CustomId, which uniquely identifies a player and CreateAccount, which allows the creation of a new account with this call. TitleId is another mandatory parameter in JavaScript, and it must match PlayFab.settings.titleId
126+
* PlayFabClientSDK.LoginWithCustomID(loginRequest, LoginCallback);
127+
* This begins the async request to "LoginWithCustomID", which will call LoginCallback when the API call is complete
128+
* For login, most developers will want to use a more appropriate login method
129+
* See the [PlayFab Login Documentation](https://api.playfab.com/Documentation/Client#Authentication) for a list of all login methods, and input parameters. Common choices are:
130+
* [LoginWithAndroidDeviceID](https://api.playfab.com/Documentation/Client/method/LoginWithAndroidDeviceID)
131+
* [LoginWithIOSDeviceID](https://api.playfab.com/Documentation/Client/method/LoginWithIOSDeviceID)
132+
* [LoginWithEmailAddress](https://api.playfab.com/Documentation/Client/method/LoginWithEmailAddress)
133+
* LoginCallback contains two parameters: result, error
134+
* When successful, error will be null, and the result object will contain the requested information, according to the API called
135+
* This result contains some basic information about the player, but for most users, login is simply a mandatory step before calling other APIs.
136+
* If error is not null, your API has failed
137+
* API calls can fail for many reasons, and you should always attempt to handle failure
138+
* Why API calls fail (In order of likelihood)
139+
* PlayFabSettings.TitleId is not set. If you forget to set titleId to your title, then nothing will work.
140+
* Request parameters. If you have not provided the correct or required information for a particular API call, then it will fail. See error.errorMessage, error.errorDetails, or error.GenerateErrorReport() for more info.
141+
* Device connectivity issue. Cell-phones lose/regain connectivity constantly, and so any API call at any time can fail randomly, and then work immediately after. Going into a tunnel can disconnect you completely.
142+
* PlayFab server issue. As with all software, there can be issues. See our [release notes](https://api.playfab.com/releaseNotes/) for updates.
143+
* The internet is not 100% reliable. Sometimes the message is corrupted or fails to reach the PlayFab server.
144+
* If you are having difficulty debugging an issue, and the information within the error information is not sufficient, please visit us on our [forums](https://community.playfab.com/index.html)

PlayFabSDK/PlayFabAdminApi.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if(!PlayFab.settings) {
1818
if(!PlayFab._internalSettings) {
1919
PlayFab._internalSettings = {
2020
sessionTicket: null,
21-
sdkVersion: "0.35.170102",
21+
sdkVersion: "0.36.170109",
2222
buildIdentifier: "jbuild_javascriptsdk_1",
2323
productionServerUrl: ".playfabapi.com",
2424

PlayFabSDK/PlayFabClientApi.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if(!PlayFab.settings) {
1818
if(!PlayFab._internalSettings) {
1919
PlayFab._internalSettings = {
2020
sessionTicket: null,
21-
sdkVersion: "0.35.170102",
21+
sdkVersion: "0.36.170109",
2222
buildIdentifier: "jbuild_javascriptsdk_1",
2323
productionServerUrl: ".playfabapi.com",
2424

PlayFabSDK/PlayFabMatchmakerApi.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if(!PlayFab.settings) {
1818
if(!PlayFab._internalSettings) {
1919
PlayFab._internalSettings = {
2020
sessionTicket: null,
21-
sdkVersion: "0.35.170102",
21+
sdkVersion: "0.36.170109",
2222
buildIdentifier: "jbuild_javascriptsdk_1",
2323
productionServerUrl: ".playfabapi.com",
2424

PlayFabSDK/PlayFabServerApi.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if(!PlayFab.settings) {
1818
if(!PlayFab._internalSettings) {
1919
PlayFab._internalSettings = {
2020
sessionTicket: null,
21-
sdkVersion: "0.35.170102",
21+
sdkVersion: "0.36.170109",
2222
buildIdentifier: "jbuild_javascriptsdk_1",
2323
productionServerUrl: ".playfabapi.com",
2424

0 commit comments

Comments
 (0)