Saving, acquiring, and deleting application data
Saving application data
OpenSocial allows data to be saved in a container. Application data in a container can be saved, acquired, or deleted through the API.
The following contains sample code for saving an application:
- Call opensocial.newDataRequest() and create a DataRequest.
- Call newUpdatePersonAppDataRequest() in the generated DataRequest and generate a request.
- Specify the owner of the application data (VIEWER cannot be changed), the data key and values in the arguments.
- Call DataRequest.add(request) and register the request.
- Call DataRequest.send(callback) and make a request to acquire information.
- Once the server request process is complete, the callback function specified with send() is executed using the DataResponse that contains the request results as an argument.
- Process the data that is stored in DataResponse.
Acquiring application data
The following contains sample code for acquiring application data that has been saved by a VIEWER:
- Generate the IdSpec that indicates the owner of application data using opensocial.newIdSpec(). Now specify the VIEWER.
- Call opensocial.newDataRequest() and create a DataRequest.
- Call newUpdatePersonRequest() from the DataRequest that was generated to acquire information on the VIEWER, and generate a request.
- Call DataRequest.add(request) and register the request.
- Call newUpdatePersonAppDataRequest() and generate a request.
- Specify the IdSpec, which identifies the owner of the application data, and the data key with an array in the arguments.
- Call DataRequest.add(request) and register the request.
- Call DataRequest.send(callback) and make a request to acquire information.
- Once the server request process is complete, the callback function specified with send() is executed using the DataResponse that contains the request results as an argument.
- Process the data that is stored in DataResponse.
Next, acquire the application data that was saved by the VIEWER's Mobatomo (Friend).
- Generate the IdSpec that indicates the owner of the application data using opensocial.newIdSpec(). Now specify the VIEWER’s FRIENDS.
- Call opensocial.newDataRequest() and create a DataRequest.
- Call newUpdatePersonAppDataRequest() and generate a request.
- Specify the IdSpec, which identifies the owner of the application data, and the data key with an array in the arguments.
- Call DataRequest.add(request) and register the request.
- Call DataRequest.send(callback) and make a request to acquire information.
- Once the server request process is complete, the callback function specified with send() is executed using the DataResponse that contains the request results as an argument.
- Process the data that is stored in DataResponse.
Deleting application data
Follow the steps below to delete saved application data:
- Call opensocial.newDataRequest() and create a DataRequest.
- Call newUpdatePersonRemoveDataRequest() in the generated DataRequest and generate a request.
- Specify the owner of the application data (VIEWER cannot be changed) and the data key in the arguments.
- Call DataRequest.add(request) and register the request.
- Call DataRequest.send(callback) and make a request to acquire information.
- Once the server request process is complete, the callback function specified with send() is executed using the DataResponse that contains the request results as an argument.
- Process the data that is stored in DataResponse.
Restrictions on application data
There are currently several restrictions on the use of application data:
- Saving and deleting application data is restricted to the application data of the VIEWER.
- Acquiring application data is restricted to the application data of the VIEWER and the VIEWER’s FRIENDS.
- The size restrictions on keys and values are 32 bytes and 1024 bytes, respectively.
- Key and value pairs are restricted to 30 per user with an installed application.
Revision History
- 12/2010
- Initial Release.