Tuesday, July 19, 2011

Code sample to access SkyDrive Photos API from WP7 (or any REST/OAuth/JSON enabled device/OS)

Microsoft Developer Network - SkyDrive Photo API sample for WP7

"The code sample shows how to access a user's SkyDrive photos using the SkyDrive APIs. It shows how to sign-in the user, get their permission to access their data and then access their data using RESTful interfaces. The sample shows the best practices for interacting with Windows Live's OAuth 2.0 end point and is a pattern that can be followed on other mobile platforms such as Android or iOS.

Building the Sample

The sample requires a valid client ID to be placed in the code to compile. Go to the Windows Live application management site to create a valid client ID.


The sample shows how to construct a URL that the when navigated to in a WebBrowser control takes the user through signing into Windows Live, granting the application permission to access their data and which returns an OAuth 2.0 access token that the application can then use to make subsequent calls to the SkyDrive API.


Source Code Files

  • UserInfo.cs - represents the data returned by the JSON request for a user's information
  • AlbumInfo.cs - represents the data returned by the JSON request for a user's photo albums
  • MainPage.xaml.cs - This is where the bulk of the application logic lives.


Interesting... Not sure I've seen a complete working example like this. Heck I wasn't aware that the Windows Live SDK - REST API had this level of SkyDrive Photo support. Given the "Windows Live Messenger Connect" title on the API, I didn't even think to look for SkyDrive support in it... funny that... :/

No comments: