Facebook

AppId and appName

This tutorial will guide you through the process of setting appName and appId arguments in login command. Full documentation of this command is available here: http://developers.xstore.pro/documentation#login

Commands used in this tutorial:

  • login.

Before you start...

  • We assume that you have at least basic knowledge of xAPI and you are able to establish a connection and login to the server,
  • You will also need Java wrapper (available here: http://developers.xstore.pro/api/wrappers) or be able to use all commands listed above by yourself.

The concept behind the appName and appId arguments

In order to get full access to xApi functions you have to be successfully logged in first. Logging is performed with use of login command, which as arguments takes userId, password, appName and appId. Although your login command will be accepted if you only pass userId and password, you should also consider passing those other two arguments describing your application. If you decide to do that, be aware that there is a difference when you log in to demo and real servers. In general the rules are:

  1. The appName is simply a name of your application. It may be the same for both real and demo servers, but for practical reasons it is wise to distinguish those two by adding adequate suffixes, i.e. "<your application name> DEMO" or "<your application name> REAL".
  2. The appId argument is obtained through contact with xStore Support Team. This argument is only applicable when connecting to real servers and must be omitted when logging in to demo servers. The appId is a unique application identificator and is useful if you want your application to be placed on xStore.pro. When a user buys the application in our store, the system matches his userId to appId of the application he bought. Thus, we provide our developers with a simple way to limit access to their applications only to the verified users.

Examples

First example presents properly set JSON object used to log in to DEMO server. Notice that the field appId is omitted.

{
	"command": "login",
	"arguments": {
		"userId": 100,
		"password": "PASSWORD",
		"appName": "Test application DEMO"
	}
}

For the purposes of the next example let’s say you have received from xStore Support Team a unique application identificator which equals to 172338. JSON object used to log in to REAL server should be set as follows:

{
	"command": "login",
	"arguments": {
		"userId": 100,
		"password": "PASSWORD",
		"appName": "Test application REAL",
		"appId": "172338"
	}
}

Next two examples are equivalent to the previous ones with the only difference that they use Java wrapper to execute the login command instead of sending the JSON object to the server manually. In order to log in with use of Java wrapper you have to create an instance of the Credentials class (notice that this class provides several constructors) and pass it together with an appropriate SyncAPIConnector object to the executeLoginCommand static method from the APICommandFactory class. See the listings for details:

Credentials credentials = new Credentials(100L, "PASSWORD", "<app name> DEMO");

ServerEnum server = ServerEnum.DEMO;		
SyncAPIConnector connector = new SyncAPIConnector(server);

APICommandFactory.executeLoginCommand(connector, credentials);

Logging in to REAL server with Java wrapper:

	
Credentials credentials = new Credentials(100L, "PASSWORD", "<app name> REAL", "172338");

ServerEnum server = ServerEnum.REAL;		
SyncAPIConnector connector = new SyncAPIConnector(server);

APICommandFactory.executeLoginCommand(connector, credentials);

Summary

In this tutorial you have learned how to use appName and appId fields when logging in to xAPI.