Contents |
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.
The URI accepts parameters as part of the URI. URIs are of the following form:
This can be one of the following values:
| 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. |
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 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