MySpace Developer Platform

A Place For Developers
From MySpace Open Platform: Documentation Wiki

OpenSocial v0.9 AppData

Jump to: navigation, search

Contents

Base URI

The base uri for AppData on MySpace is http://opensocial.myspace.com/roa/09/appdata. This endpoint supports GETs, PUTs, POSTs, and DELETEs.

URI Parameters

The URI accepts parameters as part of the URI. URIs are of the following forms

{personId}

This can be one of the following values:

  • @me: Refers to the current user. @me can only be passed in when using the xoauth_requestor_id query string parameter or when passing in an OAuth token.
  • An integer value: MySpace IDs are integers. For example, Tom is 6221. 6221 is a valid integer value.
  • myspace.com.person.[integer value]: PersonIDs also support type identifier prepended to the integer value. Tom's value is myspace.com.person.6221.

{selector}

This can be one of the following values:

  • @self: Refers to the user named in {personId}.
  • @all/@friends: Retrieves application data from all friends but NOT from {personId}.
  • GroupId - the ID of the user’s custom group:
    • Must be a MySpace group ID, retrieved from the OpenSocial0.9Groups Groups endpoint.
    • myspace.com.group.[integer value]: GroupIDs also support type identifier prepended to the integer value.

{appId}

This must be the application ID associated with the OAuth ConsumerKey/ConsumerSecret pair.

Notes

  • The MySpace data contract for AppData is different than the OpenSocial 0.9 spec, please take a look at the examples/SDKs to get more idea as to how it looks.
  • Apps must be installed to call any AppData endpoint.
  • For @friends/@all/groupId calls, the application needs to have permission to access the user’s friends’ data.
  • UPDATE/DELETE only works for @self requests and only if the person is the viewer.
  • For any {selector} value (note – for @self as well), FETCH requests will always return as a collection in the response. Check out the examples for more details.
  • The ApplicationId in the URI and the authorization context needs to be the same.
  • The response URI for the UPDATE AppData endpoint is actually the resource URI to that application-user AppData entry.
  • The UPDATE endpoint will ignore any key with null values in the list. Use the DELETE endpoint instead to remove any key.
  • Use the @fields query parameter to FETCH/DELETE specific key(s). If @fields is not passed or is set to @all, it will FETCH/DELETE all of the user’s AppData.
  • The call to FETCH appdata of a particular custom group of friends is generally an expensive call, so try to avoid it if possible.

Filtering Results

OpenSocial supports a set of standard query parameters for filtering data. Depending on the endpoint, different sets of query parameters are supported with different, well known values.

  • count: Not Supported.
  • fields: Supported. The fields correspond to keys in the AppData. One uses fields to only retrieve specific keys. If the request omits fields, all AppData per user will be returned.
  • filterBy: Not supported.
  • filterOp: Not supported.
  • filterValue: Not supported.
  • format: Determines the format of the response. We currently support json and xml.
  • networkDistance: Not supported.
  • sortBy: Not supported.
  • sortOrder: Not supported.
  • startIndex: Not supported.
  • updatedSince: Not supported.

Examples

Like all OpenSocial endpoints, the AppData endpoint requires OAuth parameters in all requests. The examples on this page do not show the OAuth parameters.

Retrieve all AppData for a single user

Request: http://opensocial.myspace.com/roa/09/appData/@me/@self/135473

Response:

{
  "entry":[
     {"userAppData":{
       "appData":[
          {"key":"key1","value":"value1"},
          {"key":"key2","value":"value2"}],
       "personId":"myspace.com.person.478499510"}}],
  "itemsPerPage":"1",
  "startIndex":"0",
  "totalResults":"1"
}

PHP Sample

/**
 * Get viewer's app data
 * @using osapi PHP SDK 
 */
 
require_once "osapi/osapi.php";
 
$appKey = '<app key>';
$appSecret = '<app secret>';
$userId = '<userId>';
 
$osapi = new osapi(new osapiMySpaceProvider(), new osapiOAuth2Legged($appKey, $appSecret, $userId));
$batch = $osapi->newBatch();
 
$app_data_self_params = array(
  'userId' => $userId, 
  'groupId' => '@self', 
  'appId' => '@app'
);
$batch->add($osapi->appData->get($app_data_self_params), 'appdataSelf');
 
// Send all batched commands
$result = $batch->execute();
 
// Demonstrate iterating over a response set, checking for an error & working with the result data. 
foreach ($result as $key => $result_item) {
    if ($result_item instanceof osapiError) {
      echo "<h2>There was a <em>".$result_item->getErrorCode()."</em> error with the <em>$key</em> request:</h2>";
      echo "<pre>".htmlentities($result_item->getErrorMessage())."</pre>";
    } else {
      echo "<h2>Response for the <em>$key</em> request:</h2>";
      echo "<pre>".htmlentities(print_r($result_item, True))."</pre>";
    }
}

Request: http://opensocial.myspace.com/roa/09/appData/@me/@self/135473?format=xml

Response:

<response xmlns="http://ns.opensocial.org/2008/opensocial" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
  <entry>
    <entry>
      <userAppData>
        <appData>
          <entry>
            <key>key2</key>
            <value>value2</value>
          </entry>
          <entry>
            <key>key1</key>
            <value>value1</value>
          </entry>
        </appData>
        <personId>myspace.com.person.478499510</personId>
      </userAppData>
    </entry>
  </entry>
  <itemsPerPage>1</itemsPerPage>
  <startIndex>0</startIndex>
  <totalResults>1</totalResults>
</response>

Retrieve a single key from AppData for a single user

Request: http://opensocial.myspace.com/roa/09/appData/@me/@self/135473?fields=test

Response:

{
  "entry":[
     {"userAppData":{
       "appData":[
          {"key":"test","value":"keyvalue"}],
       "personId":"myspace.com.person.478499510"}}],
  "itemsPerPage":"1",
  "startIndex":"0",
  "totalResults":"1"
}

PHP Sample

/**
 * Get viewer's app data
 * @using osapi PHP SDK 
 */
 
require_once "osapi/osapi.php";
 
$appKey = '<app key>';
$appSecret = '<app secret>';
$userId = '<userId>';
 
$osapi = new osapi(new osapiMySpaceProvider(), new osapiOAuth2Legged($appKey, $appSecret, $userId));
$batch = $osapi->newBatch();
 
$app_data_self_params = array(
  'userId' => '@me', 
  'groupId' => '@self', 
  'appId' => '@app',
  'fields' => 'test'
);
$batch->add($osapi->appData->get($app_data_self_params), 'appdataSelf');
 
// Send all batched commands
$result = $batch->execute();
 
// Demonstrate iterating over a response set, checking for an error & working with the result data. 
foreach ($result as $key => $result_item) {
    if ($result_item instanceof osapiError) {
      echo "<h2>There was a <em>".$result_item->getErrorCode()."</em> error with the <em>$key</em> request:</h2>";
      echo "<pre>".htmlentities($result_item->getErrorMessage())."</pre>";
    } else {
      echo "<h2>Response for the <em>$key</em> request:</h2>";
      echo "<pre>".htmlentities(print_r($result_item, True))."</pre>";
    }
}

Request: http://opensocial.myspace.com/roa/09/appData/@me/@self/135473?fields=test&format=xml

Response:

<response xmlns="http://ns.opensocial.org/2008/opensocial" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
  <entry>
    <entry>
      <userAppData>
        <appData>
          <entry>
            <key>test</key>
            <value>keyvalue</value>
          </entry>
         </appData>
        <personId>myspace.com.person.478499510</personId>
      </userAppData>
    </entry>
  </entry>
  <itemsPerPage>1</itemsPerPage>
  <startIndex>0</startIndex>
  <totalResults>1</totalResults>
</response>

Add/Update a single key to AppData for a single user

Request: POST http://opensocial.myspace.com/roa/09/appData/@me/@self/135473?fields=test

{"userId":398672205,
 "appData":[{"key":"test","value":"whatever"}]}

Response:

{"statusLink":"http:\/\/opensocial.myspace.com\/roa\/09\/appdata\/myspace.com.person.495184236\/@self\/myspace.com.app.150086"}

PHP Sample

/**
 * Update specific app data
 * @using osapi PHP SDK 
 */
 
require_once "osapi/osapi.php";
 
$appKey = '<app key>';
$appSecret = '<app secret>';
$userId = '<userId>';
 
$osapi = new osapi(new osapiMySpaceProvider(), new osapiOAuth2Legged($appKey, $appSecret, $userId));
$batch = $osapi->newBatch();
 
// Update app data for the current user
$update_params = array(
  'userId' => '@me', 
  'groupId' => '@self', 
  'appId' => $appId,
  'data' => array(
    'osapiFoo1' => date("c")
  )
);
 
$batch->add($osapi->appData->update($update_params), 'updateAppData');
 
// Send all batched commands
$result = $batch->execute();
 
// Demonstrate iterating over a response set, checking for an error & working with the result data. 
foreach ($result as $key => $result_item) {
    if ($result_item instanceof osapiError) {
      echo "<h2>There was a <em>".$result_item->getErrorCode()."</em> error with the <em>$key</em> request:</h2>";
      echo "<pre>".htmlentities($result_item->getErrorMessage())."</pre>";
    } else {
      echo "<h2>Response for the <em>$key</em> request:</h2>";
      echo "<pre>".htmlentities(print_r($result_item, True))."</pre>";
    }
}

Delete single key to AppData for a single user

Request: DELETE http://opensocial.myspace.com/roa/09/appData/@me/@self/135473?fields=test

Response:

200 OK

PHP Sample

/**
 * Delete specific app data
 * @using osapi PHP SDK 
 */
 
require_once "osapi/osapi.php";
 
$appKey = '<app key>';
$appSecret = '<app secret>';
$userId = '<userId>';
 
$osapi = new osapi(new osapiMySpaceProvider(), new osapiOAuth2Legged($appKey, $appSecret, $userId));
$batch = $osapi->newBatch();
 
$delete_params = array(
  'userId' => '@me', 
  'groupId' => '@self',
  'appId' => '@app', 
  'fields' => array('osapiFoo1')
);
$batch->add($osapi->appData->delete($delete_params), 'deleteAppData');
 
// Send all batched commands
$result = $batch->execute();
 
// Demonstrate iterating over a response set, checking for an error & working with the result data. 
foreach ($result as $key => $result_item) {
    if ($result_item instanceof osapiError) {
      echo "<h2>There was a <em>".$result_item->getErrorCode()."</em> error with the <em>$key</em> request:</h2>";
      echo "<pre>".htmlentities($result_item->getErrorMessage())."</pre>";
    } else {
      echo "<h2>Response for the <em>$key</em> request:</h2>";
      echo "<pre>".htmlentities(print_r($result_item, True))."</pre>";
    }
}