MySpace Developer Platform

A Place For Developers
From MySpace Open Platform: Documentation Wiki

OpenSocial 0.9 MediaItems

Jump to: navigation, search

Contents

Base URI

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

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}

The selector indicates which set of individuals to query for albums. Valid values are:

  • @self: This identifies a group of 1. The 1 is the person identified by {personId}.

{albumId}

The albumId indicates which group of media items from a single album from the group identified by {selector} should be returned. This is used when an application wants to display the contents of a single album. Valid values are:

  • An integer value: Gives the integer identifier of the album.
  • myspace.com.album.[integer value]
  • @videos if the media items are videos. On MySpace, videos do not belong to specific albums.

{mediaItemId}

The mediaItemId indicates which single media item from the album identified by {albumId} should be returned. This is used when an application wants to display a single mediaItem. Valid values are:

  • An integer value: Gives the integer identifier of the mediaItem.
  • myspace.com.mediaItem.image.[integer value] for image
  • myspace.com.mediaItem.video.[integer value] for video

{categoryId}

The specific video category that you want to retrieve data about.

Notes

  • The following are the default fields for the mediaItems endpoint and will always be returned
    • id
    • title
    • type
    • thumbnailUrl
    • url
  • The following fields are not supported by MySpace in OpenSocial 0.9
    • fileSize
    • location
    • lastUpdated
    • startTime
    • taggedPeople
  • The following fields are supported for Images
    • albumId
    • created
    • id
    • mimeType
    • msMediaItemUri
    • msNumTags
    • numComments
    • numViews
    • title
    • type
    • thumbnailUrl
    • url
  • The following fields are supported for Videos
    • created
    • description
    • duration
    • id
    • language
    • location
    • msMediaItemUri
    • msPrivacyLevel
    • msCategories
    • numComments
    • numViews
    • numVotes
    • rating
    • tags
    • title
    • type
    • thumbnailUrl
    • url
  • The following are MySpace extended fields
    • msMediaItemUri – URI for the mediaItem resource
    • msNumTags - returns the number of image tags
    • msPrivacyLevel - this field is only supported for Videos. Its value indicates the video’s privacy level. Possible values are
      • me - Video is private.
      • everyone – Video is visible to everyone.
      • friendsonly - Video is visible to friends only (This will be available in near future)
      • unknown - The privacy level can't be determined (This will be available in near future)
  • MediaItem endpoints only support @self requests.
  • The privacy level for an image will be inherited from the privacy level of the album it belongs to.
  • On MySpace, videos do not belong to specific albums, use @videos for the albumId instead.
  • The video(s) will only be returned if they are processed successfully and approved.
  • The URI in the response of an upload/update request is the actual URI for that MediaItem resource.
  • If an album is empty it will return nothing (totalResults = 0) if the person is the viewer. Otherwise it will return a 404.
  • A 404 will be returned if the image does not belong to the passed in albumId.
  • Currently for videos we only return videos that the person is the owner of. The result will not include the person’s favorites/profile videos.
  • For a mediaItem upload request, the request should contain the query parameter "type=image|video".
  • Currently we only support image uploads, and they must be uploaded one at a time.
  • For uploads, make sure to set the request’s HTTP header "Content-Type" correctly. For example: content-type="image/jpg"
  • For uploads, images must be less than 5MB and in the following formats: .jpg, .gif, .bmp, .tiff, .png
  • If the albumId in the URI is passed in as 0 or another invalid ID, the image will be uploaded to the user's default album.
  • For uploads, send the binary stream of the media item in the HTTP request body.
  • The URI returned in the response of a create/update request is the actual URI for that mediaItem resource.
  • There is no need to set albumId and id when updating a MediaItem object. The endpoint will take the values from the URI. If provided, the endpoint will make sure they are the same; otherwise an error will be returned.
  • For uploads, the app can set the image title by passing in the query parameter "caption=<some caption>". The maximum length for the title is 140 characters.
  • Only the image’s caption can be updated.
  • Only the title and description of a video can be updated. They cannot be null or empty. If a null is passed it will assume the previous value.
  • Mobile URLs in MediaItem objects can be returned by appending wap=1 to the query-string.
  • The following table lists of the various permissions and what they stand for.


Permission Permission on App Settings page Notes
Viewer_access_to_public_videos_photos App gets this permission automatically if app is installed. It will grant access to user’s public images/videos.
Viewer_access_to_private_videos_photos View my private photos & videos It will grant access to user’s private images/videos. [me and friendsonly]
Viewer_add_photos_to_albums Allow this app to upload photos. It will grant access to upload images/videos.

Note – the app can only request permission for the viewer.

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: Supported.
  • fields: Supported. Currently handles the following field names: (bold are always returned)
    • albumId
    • created
    • description
    • duration
    • id
    • language
    • mimeType
    • msMediaItemUri
    • msPrivacyLevel
    • numComments
    • numViews
    • numVotes
    • rating
    • tags
    • thumbnailUrl
    • title
    • type
    • url
    • @all: A special value that tells the REST endpoint to send back all fields for the MediaItem.
  • 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: Indicates the index of the first item to retrieve from the query set.
  • updatedSince: Not supported. There is a bug report in to address this issue.

Examples

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

Retrieve all supported fields

Request: http://opensocial.myspace.com/roa/09/albums/@supportedFields

Response:

["albumId","created","description","duration","id","language","mimeType","numComments","numViews","numVotes","rating","tags","thumbnailUrl","title","type","url"]


Request: http://opensocial.myspace.com/roa/09/albums/@supportedFields?format=xml

Response:

<ArrayOfstring
  xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays"
  xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
  <string>albumId</string>
  <string>created</string>
  <string>description</string>
  <string>duration</string>
  <string>id</string>
  <string>language</string>
  <string>mimeType</string>
  <string>numComments</string>
  <string>numViews</string>
  <string>numVotes</string>
  <string>rating</string>
  <string>tags</string>
  <string>thumbnailUrl</string>
  <string>title</string>
  <string>type</string>
  <string>url</string>
</ArrayOfstring>

PHP Sample

/**
 * Get supported fields for mediaItems
 * @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();
 
// The second option in the $batch->add() assigns a request Id.
$batch->add($osapi->mediaItems->getSupportedFields(), 'supported_fields');
 
// 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>";
    }
}

Retrieve items from an Album

Request: GET http://opensocial.myspace.com/roa/09/mediaItems/@me/@self/myspace.com.album.1224563?xoauth_requestor_id=398672205

Response:

{"entry":[
	{"mediaItem":
		{"id":"myspace.com.mediaItem.image.14002385",
		 "thumbnailUrl":"http:\/\/c2.ac-images.myspacecdn.com\/images02\/16\/s_46e99190a67b4cedaecc4d9889c8ea25.jpg",
		 "title":"","type":"IMAGE",
		 "url":"http:\/\/c2.ac-images.myspacecdn.com\/images02\/16\/l_46e99190a67b4cedaecc4d9889c8ea25.jpg"}}],
 "itemsPerPage":"1",
 "startIndex":"1",
 "totalResults":"1"}

PHP Sample

<?php
/**
 * Get mediaItems for album
 * @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();
 
$user_params = array(
    'userId' => $userId, 
    'groupId' => '@self', 
    'albumId' =>'myspace.com.mediaItem.3007062',
    'count' => 2
);
 
// The second option in the $batch->add() assigns a request Id.
$batch->add($osapi->mediaItems->get($user_params), 'get_mediaItems');
 
// 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>";
    }
}
?>

Retrieve a single MediaItem from an Album

Request: GET /roa/09/mediaItems/@me/@self/myspace.com.album.1224563/myspace.com.mediaItem.image.14002385?xoauth_requestor_id=398672205 HTTP/1.1

Response:

{"itemsPerPage":"1",
 "mediaItem":{
    "id":"myspace.com.mediaItem.image.14002385",
    "thumbnailUrl":"http:\/\/c2.ac-images.myspacecdn.com\/images02\/16\/s_46e99190a67b4cedaecc4d9889c8ea25.jpg",
    "title":"",
    "type":"IMAGE",
    "url":"http:\/\/c2.ac-images.myspacecdn.com\/images02\/16\/l_46e99190a67b4cedaecc4d9889c8ea25.jpg"},
 "startIndex":"0",
 "totalResults":"1"}

PHP Sample

/**
 * Get a specific mediaItem
 * @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();
 
$user_params = array(
    'userId' => $userId, 
    'groupId' => '@self',
    'fields'=>'@all',
    'albumId' =>'myspace.com.mediaItem.3007062',
    'mediaItemId'=>'myspace.com.mediaItem.image.52894964'
);
 
// The second option in the $batch->add() assigns a request Id.
$batch->add($osapi->mediaItems->get($user_params), 'get_mediaItems_id');
 
// 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>";
    }
}

Add a Photo to an Album

Request:

POST /roa/09/mediaItems/@me/@self/myspace.com.album.1224563?xoauth_requestor_id=398672205&type=IMAGE&caption={optional_parameter} HTTP/1.1
Host: opensocial.myspace.com
Accept: */*
Content-Type: image/jpeg
Authorization: OAuth realm="",oauth_version="1.0",oauth_nonce="e394f964b861da384b5aff543febd184",oauth_timestamp="1247183541",oauth_consumer_key="http%3A%2F%2Fwww.myspace.com%2F422699854",oauth_signature_method="HMAC-SHA1",oauth_signature="[it's a secret]"
Content-Length: 125586
 
[JPEG is here, contents elided]

Response:

{"statusLink":"http:\/\/opensocial.myspace.com\/roa\/09\/mediaitems\/myspace.com.person.398672205\/@self\/myspace.com.album.1224563\/myspace.com.mediaItem.image.14002385"}

PHP Sample

/**
 * Upload Photo
 * @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();
 
// Load file binary data
$data = file_get_contents('images.jpg');
 
$user_params = array(
    'userId' => '@me', 
    'groupId' => '@self',
    'albumId' =>'myspace.com.mediaItem.3007062',
    'mediaType'=>'IMAGE',
    'mediaItem' => $data,
    'contentType'=> 'image/jpg'
);
 
// The second option in the $batch->add() assigns a request Id.
$batch->add($osapi->mediaItems->uploadContent($user_params), 'upload_mediaItem');
 
 
// 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>";
    }
}

Update a Photo in an Album

Request: POST /roa/09/mediaItems/@me/@self/myspace.com.album.1224563/myspace.com.mediaItem.image.14002385?xoauth_requestor_id=398672205

{ "title":"This is a new title" }

Response:

{"statusLink":"http:\/\/opensocial.myspace.com\/roa\/09\/mediaitems\/myspace.com.person.398672205\/@self\/myspace.com.album.1224563\/myspace.com.mediaItem.image.14002385"}

PHP Sample

/**
 * Update Media Item then get newly updated mediaItem
 * @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->setFields('title', 'title '.time());
 
$user_params = array(
    'userId' => '@me', 
    'groupId' => '@self',
    'albumId' =>'myspace.com.mediaItem.3007062',
    'mediaItemId'=>'myspace.com.mediaItem.image.52894964',
    'mediaItem' => $mediaItem
);
 
// The second option in the $batch->add() assigns a request Id.
$batch->add($osapi->mediaItems->update($user_params), 'update_mediaItem');
 
$user_params = array(
    'userId' => '@me', 
    'groupId' => '@self',
    'albumId' =>'myspace.com.mediaItem.3007062',
    'mediaItemId'=>'myspace.com.mediaItem.image.52894964'
);
 
// The second option in the $batch->add() assigns a request Id.
$batch->add($osapi->mediaItems->get($user_params), 'get_mediaItem');
 
// 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>";
    }
}