MySpace Developer Platform

A Place For Developers
From MySpace Open Platform: Documentation Wiki

OpenSocial v0.9 Notifications

Jump to: navigation, search

Contents

Base URI

The base uri for notifications on MySpace is http://opensocial.myspace.com/roa/09/notifications. This endpoint only supports POST and PUTs at this time.

URI Parameters

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

{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.

Notes

  • The MySpace data contract for notifications is an extension of the OpenSocial 0.9 spec, please take a look at the examples/SDKs to get more idea as to how it looks.
  • To post images with a notification, pass MediaItem 0.9 OpenSocial URI as msMediaItemUri field of MediaItem(s) with the notification object.
  • Apps must be installed to call the notifications endpoint.
  • Notification endpoints only support @self requests.
  • Notification endpoints only support POST or PUT HTTP methods.
  • You must specify at least one user ID in the recipientIds field of the posted object. Failure to do so, will generate a 400 - Bad Request.
  • As with all MySpace OpenSocial REST endpoints, more information about a particular error response can be found in the "x-opensocial-error" response header.
  • The following table lists of the various permissions and what they stand for.
Permission Permission on App Settings page Notes
Allow_Receiving_Notifications Receive notifications from this app It will grant access for an app to send you a notification.

Examples

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

Send a notification

PHP Example

/**
 * Send notification
 * @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();
 
$mediaItem = new osapiMediaItem();
$mediaItem->setField('uri', 'http://api.myspace.com/v1/users/63129100');
 
$notification = new osapiNotification();
$notification->setField('recipientIds', array('<myspace userId here>'));
$notification->setField('mediaItems', array($mediaItem));
$notification->setTemplateParameter('content', 'Hi ${recipient}, here\'s a notification from ${canvasUrl}');
 
$params = array('notification'=>$notification);
 
// Second parameter is a request id
$batch->add($osapi->notifications->create($params), 'send_notification');
 
// 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: POST http://opensocial.myspace.com/roa/09/notifications/@me/@self

{
  "mediaItems":[{"msMediaItemUri":"http:\/\/opensocial.myspace.com\/roa\/09\/mediaItems\/1234\/@self\/1234\/5678"}],
  "recipientIds":["myspace.com.person.6221"],
  "templateParameters":[{"key":"canvasUrl","value":"myCanvasUrl"},{"key":"content","value":"myContent"}]
}


Response: 201 - Created