In this example we will make a REST call to MySpace, get back 100 of our friends and display them on a web page. Because we’re accessing personal private information, you need to pass some authorization parameters with your REST call, and MySpace has adapted the OAuth authorization standard. Before I start explaining more about the code, make sure you already have a MySpace account, then follow the next few steps:
- Go to: http://developer.myspace.com/ and
- Click on Build on the top nav.
-
- Select Create on-site app button, and fill out your app info.
- When you get to the section for upload app xml, click on skip this step.
- Make a note of your OAuth Consumer Key and OAuth Consumer Secret because you will need it later.
- Under the Canvas Surface tab, select External IFrame option.
- Then you have to add the app, otherwise you may get 401 access denied error attempting to make a request.
Okay, hit save and you should be good for now. Let’s open up Visual Studio 2008 and begin!
- Create a Website called MySpaceApp or whatever you want.
- Copy this file OAuthBase.cs into your project
- Add using OAuth namespace at the top of Default.cs
- Declare variables for your consumer key, consumer secret and request server:
protected string consumerKey = "http://www.myspace.com/123456789";
protected string consumerSecret = "12abcd345678efghi90jk";
protected string requestServer = "http://api.myspace.com";
- Create a public MakeRequest() method returning a DataSet.
public DataSet MakeRequest(string restCall)
{
// Form the full REST request url
Uri url = new Uri(requestServer + restCall);
DataSet ds = new DataSet();
// Instantiate OAuthBase and declare variables
OAuthBase oAuth = new OAuthBase();
string nonce = oAuth.GenerateNonce();
string timeStamp = oAuth.GenerateTimeStamp();
string normUrl = string.Empty;
string normParams = string.Empty;
string strRequest = string.Empty;
// Create an OAuth signature
string signature = oAuth.GenerateSignature(url,
consumerKey, consumerSecret, string.Empty, string.Empty,
"GET", timeStamp, nonce, OAuth.OAuthBase.SignatureTypes.HMACSHA1,
out normUrl, out normParams);
// Construct the OAuth authenticated REST url
strRequest = normUrl + "?" + normParams + "&" + UrlEncode("oauth_signature") + "=" + UrlEncode(signature);
return MakeWebRequest(strRequest);
}
- Next create a MakeWebRequest() method returning a DataSet
protected DataSet MakeWebRequest(string restCall)
{
// Make web request
HttpWebRequest request = WebRequest.Create(restCall) as HttpWebRequest;
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
// In this example we are getting back XML
XmlTextReader xReader = new XmlTextReader(response.GetResponseStream());
DataSet ds = new DataSet();
ds.ReadXml(xReader);
xReader.Close();
return ds;
}
}
-
Finally create a GetFriendList() method that will make the REST request and bind it to a Repeater displaying all your friends.
protected void GetFriendList()
{
rptFriends.DataSource = fb.MakeRequest("/v1/users/YOUR_USER_ID/friends.xml?page_size=100");
rptFriends.DataBind();
}
- I also built this REST Test Tool that uses OAuthBase.cs that will help you create sample REST calls so you can validate the OAuth parameters.
Filed Under (ASP.NET, Javascript) by Steve on 01-03-2009
About 2 years ago I posted an article called “Quick Ajax Example Using Prototype.js” and some visitors commented that my instructions weren’t clear so I just wanted to post a quick follow up. This is basically the same example using the more efficient jQuery library.
- Create a file named ShowTime.aspx that will display the current time when the page is called. Follow steps 1-4 from my old article.
- Create a ShowTime.html file with a link
<a id="gettime" href="#">click to see updated time without page refresh</a> and a <div id="time"></div> to display the updated time when the link is clicked.
- Call jQuery library from google between your tags like this
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type="text/javascript"></script>
- Now add this jQuery script inside the
<script> tags after calling jQuery library.
$(function(){
$("#gettime").click(function(){
$("#time").load("http://dev.hostreaction.net/examples/showtime.aspx");
});
});
- Check out the demo and view source to get the exact HTML and jQuery.
- To briefly explain what’s going on in step 4: everything between the
$(function(){ ... }); loads as soon as the DOM is loaded. Then we attach a “click” event to the “gettime” link (notice the # sign corresponding to the link ID attribute, jQuery uses CSS selectors). Inside the “click” event we run the .load function which is an ajax call to “showtime.aspx” and we tell it to display it to <div id="time"></div> element.
First let me explain what nav links i’m talking about and how they’re created by Peformance Point 2007 Dashboard Designer. These nav links appear at the top of the default Dashboard and represent the different pages of reports. They are automatically generated by Dashboard Designer by injecting JavaScript into a DIV element called “ppsmaPageOverview”. It starts off by creating a label and container for the dashboard with this function “createPageOverview”. Then the related pages are called with this function “createPageOverviewTab”, these functions also check for a property to see if that tab is selected or not (all this done dynamically with JavaScript). This is not the most elegant method of generation navs, but that’s how Dashboard Designer does it.
So alot of times I’m asked to modify those links, like the layout, rename links or even add a custom link that can’t be generated by Dashboard Designer. This product is so new that solutions for this tasks aren’t posted yet, which forces me to come up with a solution. I’m not saying my solution is the best, if someone from Microsoft could chime in or email me a better solution then i’d gladly thank them and use it!
Ok I was asked to add a “Print Report” link to the auto-generated list navigation. My workaround was to create a new “Web Page” from “Report Templates” and in that web page I entered the link to an auto-generated PDF file. That was it, you can of course create a custom aspx page that embeds your PDF or has custom controls on it and link to that in the “Web Page” as well.
Filed Under (ASP.NET, SharePoint) by Steve on 09-09-2008
Blame it on those dumb hidden fields:
<input type="text" name="__spDummyText1" style="display:none;" size=1/>
<input type="text" name="__spDummyText2" style="display:none;" size=1/>
Place them between
and after “PlaceHolderMain”.
I spent hours trying to figure out the cause of this on Firefox, even tried writing some custom JS but in the end all i needed to do was include these in my master page!
Filed Under (Television) by Steve on 26-07-2008
Just testing all features of the wordpress iPhone app. So far it’s a clean interface which males it easy to navigate. I’ll take a pic and see how nicely it integrates. However previewing a post the layout rendering was a little funky. Overall it seems to work well and is a convienent app for posting from the couch.
Update: the app crashed when trying to take a new photo and attach it. Gonna try again. Funky markup was due to some ads, photo worked second time around but I guess you can’t position the photo. Also be sure to hit DONE to finish up your post and SAVE to publish.

I recently had to work with Akamai Secure Flash Sreaming for on-demand videos and wanted to share some notes on how we got this to work.
You’ll need 2 zip files from Akamai:
- Akamai Flash Media Kit
- Akamai Secure Token Generator
Inside the Akmai Flash Media Kit you will have to open CS3SampleOnDemand.fla in Flash and edit the ActionScript. First declare a constant for the token:
CONNECTION_AUTH_PARAMS=”THEVALUEFROMYOURFLASHVARS_TOKEN”;
Then you will pass the autorization token to the Akamai object like this:
ak.authParams = CONNECTION_AUTH_PARAMS;
I also have a DLL with using the Type D Authentication from Akamai, please email me if you need it.
Filed Under (ASP.NET, Development) by Steve on 01-07-2008
Sometimes some projects visually hide the SharePoint navigation links so I wanted to list some here because I can never remember them:
Site Content and Structure – sitemanager.aspx
All Site Content – viewlsts.aspx
Site Content Type Gallery – mngctype.aspx
Site Features – ManageFeatures.aspx
More to come…
It’s a small change, but I always forget how to do this so I’m blogging it! Locate the siteMapPath control in the Master Page and add a PathSeperator attribute shown in the example below:
<asp:SiteMapPath ID="siteMapPath" Runat="server"
SiteMapProvider="CurrentNavSiteMapProviderNoEncode" RenderCurrentNodeAsLink="false" SkipLinkText="" NodeStyle-CssClass="ms-sitemapdirectional" PathSeparator=" / "/>
Filed Under (Uncategorized) by Steve on 15-06-2008
When the Lakers lost game 4 it hurt, I felt like someone punched me in the guy, kicked me in the balls and stole my wallet. But losing that game meant something bigger, it meant that every game from here on is an elimination game for the Lakers. I’m pretty nervous today and at this point will be happy if they make it to 7 games.
Filed Under (Cars) by Steve on 03-06-2008
Even though I wish the aptera was available to check out. Well i’ve negotiated what I think is an okay lease but still trying see what the best deal is since we’re in a little recession and gas prices are rising.
Here’s what I’ve negotiated so far, has anyone gotten a better deal?
- 2008 G37: Premium, Sport, Nav
- 39mo, 15000 miles
- $900 due at signing
- $536 a month