Welcome Developers!

in

Welcome!

in

OpenSocial 0.9 Albums API

 

One feature we added in OpenSocial 0.9 is Albums. Albums include MediaItems: photos, movies, and songs. Several of the containers out there, including MySpace, already had different views of what an album is. For example, on our platform you can access an album today via the REST URI (/v1/users/[user id]/albums/[album id]) (docs here). The big benefit of OpenSocial is that the group standardizes how all this works so that an application written for MySpace using only OpenSocial APIs should work for Orkut, Hi5, Yahoo!, or any other container. Album support was introduced in a few different areas:

  • Support to the OpenSocial JavaScript library.
  • Support to the RESTful API
  • Support in the OpenSocial RPC library (an optional part of the spec not supported by MySpace at this time)

Let's take a look at the required parts of the albums support.

JavaScript changes

First, we added a bunch of new methods to fetch, add, update, and remove Albums and MediaItems. First, the methods that allow one to fetch information:

  • opensocial.newFetchAlbumsRequest(idSpec, opt_params): Creates an object for DataRequest to request albums. opt_params can specify the following:
  • o opensocial.Album.Field.ID - an array of album Ids to fetch (fetch all albums if empty, subject to pagination)
  • o opensocial.Album.Field.MEDIA_TYPE - an array of MediaItem.TYPE values to specify the kind of Albums to fetch.
  • opensocial.newFetchMediaItemsRequest(idSpec, albumId, opt_params): Fetches the list of media items in an Album. opt_params can specify the following:
  • o opensocial.MediaItem.ID - an array of media item ids to selectively fetch (fetch all items if empty, subject to pagination)
  • o opensocial.MediaItem.MEDIA_TYPE - an array of MediaItem.TYPE values to specify the types of MediaItems to fetch

The usual Filter / FIRST / MAX technique is available through opt_params for pagination on newFetchAlbumsRequest and newFetchMediaItemsRequest.

We then added methods to create update, and delete albums and media items:

  • opensocial.newCreateAlbumRequest(idSpec, album): Creates a new album and returns the ID of the album created. Containers implement restrictions - like allowing a viewer to create albums for only him/herself.
  • opensocial.newCreateMediaItemRequest(idSpec, albumId, mediaItem): Creates a new media item in the album and returns the ID of the album created. Containers implement restrictions.
  • opensocial.newUpdateAlbumRequest(idSpec, albumId, fields): Updates the fields specified in the params and returns void. The following fields cannot be set: MEDIA_ITEM_COUNT, OWNER_ID, ID. Containers implement restrictions.
  • opensocial.newUpdateMediaItemRequest(idSpec, albumId, mediaItemId, fields):Updates the fields specified in the params and returns void. The following fields cannot be set: ID, CREATED, ALBUM_ID, FILE_SIZE, NUM_COMMENTS. Containers implement restrictions.
  • opensocial.newDeleteAlbumRequest(idSpec, albumId): Deletes the album specified and returns void. Containers implement restriction.
  • opensocial.newDeleteMediaItemRequest(idSpec, albumId, mediaItemId): Deletes the album specified and returns void. Containers implement restrictions.

Of course, the objects need values. We added an object and changed a few others. opensocial.Album makes its debut. The object has several fields:

  • ID - string, unique identifier for the album
  • THUMBNAIL_URL - string, URL to a thumbnail cover of the album
  • CAPTION - string, the title of the album
  • DESCRIPTION - string, description of the album
  • LOCATION - opensocial.Address, location corresponding to the album
  • OWNER_ID - string, ID of the owner of the album
  • MEDIA_TYPE - array of MediaItem.TYPE, types of MediaItems in the Album
  • MEDIA_ITEM_COUNT - integer, number of items in the album

opensocial.Activity.MediaItem was renamed to opensocial.MediaItem since it is no longer solely related to Activities. The MediaItem type earned a few new fields:

  • ID - string, id Associated with the media item
  • CAPTION - string describing the media item
  • CREATED - string, creation time associated with the media item - assigned by container in UTC
  • LAST_UPDATED - string, update time associated with the media item - assigned by container in UTC
  • THUMBNAIL_URL - string, URL to a thumbnail image of the media item
  • DESCRIPTION - string, description of the media item
  • DURATION - integer, for audio/video clips - playtime length in seconds. set to -1/not defined if unknown
  • LOCATION - opensocial.Address, location corresponding to the media item
  • LANGUAGE - string, language associated with the media item in ISO 639-3 format
  • ALBUM_ID - string, album to which the media item belongs
  • FILE_SIZE - long, number of bytes (set to -1/undefined if unknown)
  • START_TIME - string, for streaming/live content, time when the content is available
  • RATING - integer, average rating of the media item on a scale of 0-10
  • NUM_VOTES - integer, number of votes received for voting
  • NUM_COMMENTS - integer, number of comments on the photo
  • NUM_VIEWS - integer, number of views for the media item

RESTful API Changes

We added two new XRDS types: Albums and MediaItems. The RESTful API allows one to modify items in the container from external applications or through explicit XMLHttpRequests to the container. All responses from any request always come back wrapped by a Response object. These response objects have two different forms depending on whether or not the query returns a list or a single item. It is permissible for a single item to be returned in the list form. Example:

application/json representation:

{
   "startIndex":1,
   "itemsPerPage":10,
   "totalResults":100,
   "entry":[
      //{...first item...},

      //{...second item...},
      //...
   ]
}

 

or, for only one item:

{
  "startIndex" : 1
  "itemsPerPage" : 10

  "totalResults" : 100,
  "entry" : {...only item...}
}

The XML representation is

<response>

  <startIndex> 1 </startIndex>

  <itemsPerPage>

   10

  </itemsPerPage>

  <totalResults>

    100

  </totalResults>

  <entry>...first item...</entry>

  <entry>...second item...</entry>

  ...

</response>

Any responses coming back from the RESTful API will be wrapped as shown above. You can execute different HTTP verbs against the albums API and get different results. For example:

  • A GET on /albums/@me/@self with yield an array of Albums
  • A POST on /albums/@me/@self will create a new Album
  • A GET on /albums/@me/@self/albumId with return only that specific album
  • A PUT on /albums/@me/@self/albumId will update the album
  • A DELETE on /albums/@me/@self/albumId will delete the album

The returned Album will be wrapped by the response shown earlier. Getting an album, you will see something like this:

application/json representation:

{
  "id" : "44332211",
  "thumbnailUrl" : "http://pages.example.org/albums/4433221-tn.png",
  "caption" : "Example Album",
  "description" : "This is an example album, and this text is an example description",
  "location" : { "latitude": 0, "longitude": 0 },
  "ownerId" : "example.org:55443322"

}

application/xml representation:

<album xmlns="http://ns.opensocial.org/2008/opensocial">

  <id>44332211</id>

  <thumbnailUrl>http://pages.example.org/albums/4433221-tn.png</thumbnailUrl>

  <caption>Example Album</caption>

  <description>This is an example album, and this text is an example description</description>

  <location>

    <latitude>0</latitude>

    <longitude>0</longitude>

  </location>

  <ownerId>example.org:55443322</ownerId>

</album>

Once you have an album and its ID, you will want to retrieve its contents. The contents of the albums are MediaItems. Like the Album API, a different combination of HTTP verb and URL gives different results:

  • A GET on /mediaitems/@me/@self/albumId with return the media items in the album
  • A POST on /mediaitems/@me/@self/albumId can be used to create a new media item
  • A GET on /mediaitems/@me/@self/albumId/mediaItemId will return the media item
  • A PUT on /mediaitems/@me/@self/albumId/mediaItemId will update the media item
  • A DELETE on /mediaitems/@me/@self/albumId/mediaItemId will delete the mediaItem

Each MediaItem will be wrapped in a response, looking something like this:

application/json representation:

{
  "id" : "11223344",
  "thumbnail_url" : "http://pages.example.org/images/11223344-tn.png",
  "mime_type" : "image/png",
  "type" : "image",
  "url" : "http://pages.example.org/images/11223344.png",
  "album_id" : "44332211"

}


application/xml representation:

<MediaItem xmlns="http://ns.opensocial.org/2008/opensocial">

  <id>11223344</id>

  <thumbnail_url>http://pages.example.org/images/11223344-tn.png</thumbnail_url>

  <mimeType>image/png</mimeType>

  <type>image</type>

  <url>http://pages.example.org/images/11223344.png</url>

  <albumId>44332211</albumId>

</MediaItem>

OK-- that's a lot to digest.

As always, if you want to join the discussion on OpenSocial and how it is evolving, please join the container developers (we need more application developers in this conversation!) at http://groups.google.com/group/opensocial-and-gadgets-spec?hl=en.

Published Jan 07 2009, 08:00 AM by Scott
Filed under:

Comments

 

Marh-The Hood Myspace Developer said:

Will this also help with the get albums photos issue. I was using the opensocial token to make the call to grab the pictures of each album, which works in development mode but there is now way to get the opensocial token as a param anymore which is crazy. WHat should I do?

January 7, 2009 7:03 PM
 

Martin said:

test

January 8, 2009 3:55 PM
 

Misaki said:

HAPPY NEW YEAR, SCOTT! I found you because I am in desperate need of help. I can't get in contact with Tom no matter how hard I try. If this was a little thing, then I wouldn't be going through all this trouble.

Scott, please help me!! Do you think u can?

I change my password everyday, but some hacker (who doesnt reveal his name or IP address) deletes hundreds of the comments on my page!!!

Right now, he deleted 50 comments on my page all together!!!!! Other people's comments!!!! I even added a code to HIDE my comments but he somehow manages to delete them from my site!

Moreover, he keeps deleting my friends!!!!!! You guys aren't bothering me, right? Of course not, so please help me because I am a loyal MySpace member!

Scott, PLEASEEEEEEE HELP ME! WHAT CAN I DO!? That hacker thinks he's some genius who can't be caught. Can you help me so this hacker gets caught??? I contact Myspace a lot but they dont reply!!!!!

This is SOOO frustrating!!!!!! I don't know why I have to deserve this sort of stress from the hacker! I think he's one of my friends....But even if I delete all of my friends, will he STILL be able to delete the comments from my site?????

I really wish I could get in contact with Tom...Even the Myspace team members arent of any help...so I searched for you, Scott! Can you please notify Tom of this issue????

I'm Misaki from Santa Monica. I live in Santa Monica like him but I never got to see him anywhere....

I will be waiting for your response greatly. My site is private but I will accept you if u need to come and see.

Thank you!

January 25, 2009 7:11 PM
 

Misaki said:

I forgot, Scott.  Please return to misaki101@hotmail.com.

THANK YOU SOOOOOOOOO MUCH!!!!!!!!!

Misaki

January 25, 2009 7:24 PM
 

scorpion1975 said:

Hi Scott!

It seems that OpenSocial 0.9 API is not workit yet using REST API. Is there any way to create/update/delete  albums/mediaitems using MySpace REST API?

Thanks in advance!

February 10, 2009 11:03 AM
 

Alain-Christian said:

When will users be able to use tagged photos as their avatar?

March 6, 2009 6:35 PM
 

???????????? ?????? « Macroir's Blog said:

Pingback from  ???????????? ?????? &laquo; Macroir&#039;s Blog

August 10, 2010 1:45 AM
 

WinjitDeveloper said:

I am able to update status from my iphone application to my space account.But when I am trying to upload image from my iphone application on myspace account but getting error----(Error executing request(opensocial.myspace.com/.../0):Error Domain=com.myspace.mobile.errorDomainCode=2 "The operation couldn't be completed.(com.myspace.mobile.errorDomain error 2.)") can any one help me for sorting this problem?

Thanks in advance

October 13, 2011 12:13 AM
 

WinjitDeveloper said:

I am able to update status from my iphone application to my space account.But when I am trying to upload image from my iphone application on myspace account but getting error----(Error executing request(opensocial.myspace.com/.../0):Error Domain=com.myspace.mobile.errorDomainCode=2 "The operation couldn't be completed.(com.myspace.mobile.errorDomain error 2.)") can any one help me for sorting this problem?

Following are  the console details:-for myspaceId demo

[Session started at 2011-10-13 12:48:16 +0530.]

2011-10-13 12:48:22.021 MySpaceID.Demo[1893:207] AccessTokenKey (null) AccessTokenSecret (null)

2011-10-13 12:48:22.023 MySpaceID.Demo[1893:207] Access.Token.Key: iOpMKF2UezFZZoyUptLOqlxXcSen5vSJ6uyhkSslU7iglD%2FkBSuto61GHCF2bKH91Kfqyk6dbn7DqQGRUOAWFhRTor%2FarYkJeiJZZvMfYMo%3D

2011-10-13 12:48:22.023 MySpaceID.Demo[1893:207] Access.Token.Secret: 1b770a57a9fe4e6ab125002fb81a45cdf798079194f841818fcdc8cc27a598c1

2011-10-13 12:48:23.536 MySpaceID.Demo[1893:207] found an image

2011-10-13 12:48:26.063 MySpaceID.Demo[1893:207] didReceiveResponse

2011-10-13 12:48:26.064 MySpaceID.Demo[1893:207] 200

2011-10-13 12:48:26.064 MySpaceID.Demo[1893:207] didReceiveData

2011-10-13 12:48:26.065 MySpaceID.Demo[1893:207] cachedResponse

2011-10-13 12:48:26.065 MySpaceID.Demo[1893:207] connectionDidFinishLoading

2011-10-13 12:48:26.065 MySpaceID.Demo[1893:207] 200

2011-10-13 12:48:26.066 MySpaceID.Demo[1893:207] UrlRequest: opensocial.myspace.com/.../@self, Http Status Code: 200, Http Response: {"itemsPerPage":"1","numOmittedEntries":"0","person":{"displayName":"WinjitDeveloper","hasApp":"true","id":"myspace.com.person.572959346","msUserType":"RegularUser","name":{"familyName":"Nasik","givenName":"WinjitDeveloper"},"profileUrl":"http:\/\/www.myspace.com\/winjitdev","thumbnailUrl":"http:\/\/a3.l3-images.myspacecdn.com\/profile01\/137\/b1d8dd3942004a088784d44eda09ac24\/s.jpg"},"startIndex":"0","totalResults":"1"}

2011-10-13 12:48:33.574 MySpaceID.Demo[1893:207] didReceiveResponse

2011-10-13 12:48:33.575 MySpaceID.Demo[1893:207] 404

2011-10-13 12:48:33.575 MySpaceID.Demo[1893:207] didReceiveData

2011-10-13 12:48:33.576 MySpaceID.Demo[1893:207] cachedResponse

2011-10-13 12:48:33.576 MySpaceID.Demo[1893:207] connectionDidFinishLoading

2011-10-13 12:48:33.576 MySpaceID.Demo[1893:207] 404

2011-10-13 12:48:33.577 MySpaceID.Demo[1893:207] UrlRequest: opensocial.myspace.com/.../albums(null)/@self, Http Status Code: 404, Http Response: {}

2011-10-13 12:48:33.577 MySpaceID.Demo[1893:207] Method: getAlbums. Value: {}. StatusCode: 404

2011-10-13 12:48:33.614 MySpaceID.Demo[1893:207] didReceiveResponse

2011-10-13 12:48:33.615 MySpaceID.Demo[1893:207] 401

2011-10-13 12:48:33.615 MySpaceID.Demo[1893:207] connectionDidFinishLoading

2011-10-13 12:48:33.616 MySpaceID.Demo[1893:207] 401

2011-10-13 12:48:33.616 MySpaceID.Demo[1893:207] UrlRequest: opensocial.myspace.com/.../@self(null)?type=IMAGE&CAPTION=iPhonePic, Http Status Code: 401, Http Response:

2011-10-13 12:48:33.616 MySpaceID.Demo[1893:207] Method: addPhoto. Value: . StatusCode: 401

2011-10-13 12:48:33.617 MySpaceID.Demo[1893:207] Photo Upload complete

2011-10-13 12:48:37.745 MySpaceID.Demo[1893:207] didReceiveResponse

2011-10-13 12:48:37.746 MySpaceID.Demo[1893:207] 200

2011-10-13 12:48:37.746 MySpaceID.Demo[1893:207] didReceiveData

2011-10-13 12:48:37.747 MySpaceID.Demo[1893:207] cachedResponse

2011-10-13 12:48:37.747 MySpaceID.Demo[1893:207] connectionDidFinishLoading

2011-10-13 12:48:37.748 MySpaceID.Demo[1893:207] 200

2011-10-13 12:48:37.748 MySpaceID.Demo[1893:207] UrlRequest: opensocial.myspace.com/.../@self, Http Status Code: 200, Http Response: {"currentLocation":{"latitude":"0","longitude":"0"},"moodId":"87","moodName":"awake","moodPictureName":"awake.gif","moodPictureUrl":"http:\/\/x.myspacecdn.com\/images\/blog\/moods\/iBrads\/awake.gif","moodStatusLastUpdated":"2011-10-12T23:36:18","numComments":"0","resouceId":"371777778","status":"Good Morning","statusId":"634540593780000000","userId":"myspace.com.person.572959346"}

October 13, 2011 12:21 AM
 

Tyler said:

I love chicken

January 28, 2013 7:59 PM