Since I can't bring "oleh-oleh" for you all guys, all I can give is knowledge about what I get from Windows Live Training in Bangkok, April 24 - 25, 2007, CTT Training Center. I'll post as many as possible about that. The first series is what I learn today, Messenger Presence API.
Lets say you want to display your Windows Live Messenger status on the web. It's useful lets say for displaying your company's customer support, whether they're online or not. Something like these images below.
If you're not login/offline
After login & online
The status become:
How do I can make that functionality using Presence API in Windows Live?
1. Off course open your VS, I use VS 2008
2. Create new web site
3. Create a webform or HTML page that contains code like this:
<%@ Page Language="C#" AutoEventWireup="true"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="http://settings.messenger.live.com/applications/websignup.aspx?returnurl=http://localhost:50000/MessengerPresence/showmypresence.aspx&privacyurl=http://localhost:50000/MessengerPresence/privacy.htm">Show My Presence</asp:HyperLink>
</div>
</form>
</body>
</html>
Take a look at the url: http://settings.messenger.live.com/applications/websignup.aspx?
returnurl=http://localhost:50000/MessengerPresence/showmypresence.aspx&privacyurl=
http://localhost:50000/MessengerPresence/privacy.htm
If you click on that URL, it will lead us to this page below
After you login, you should see this setting page. Off course, you need to have Windows Live ID first.
This step actually is for enabling the access of our presence status. Since Windows Live is very concern to our privacy, the access of presence status is disabled by default. We just enable this one time, next time this step is unnecessary. You can go back to that setting page to disable the access.
Lets get back to the URL. That URL contains two paramaters:
- returnurl: the URL of your page that receive the result of presence query.
- privacyurl: the URL of page that displays privacy information. This page must be created but the content can be blank, but it's suggested that you display some texts about commitment of protecting user privacy in this page.
Now, we create those two pages.
4. Create showmypresence.aspx & showmypresence.aspx.cs (code behind)
showmypresence.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="showmypresence.aspx.cs" Inherits="showmypresence" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript" language="javascript">
function showpresence(presence) { var innerFrame = document.getElementById('innerFrame');
var statusIcon = document.createElement('img'); statusIcon.style.border = 'none';
statusIcon.src = presence.icon.url;
var dispName = document.createElement('span'); dispName.title = presence.displayName
dispName.innerText = presence.displayName;
var statusText = document.createElement('span'); statusText.title = presence.statusText;
statusText.innerText = presence.statusText;
var br = document.createElement('br');
innerFrame.appendChild(statusIcon);
innerFrame.appendChild(dispName);
innerFrame.appendChild(br);
innerFrame.appendChild(statusText);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label_Result" runat="server" Text="Label"></asp:Label><br />
<div id="innerFrame" style="border:solid 1px #cccccc; text-align:center; width:100px;" />
</div>
</form>
</body>
</html>
showmypresence.aspx.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Specialized;
public partial class showmypresence : System.Web.UI.Page
{ protected void Page_Load(object sender, EventArgs e)
{ string res = "";
string userid = "";
NameValueCollection returnParams = Request.QueryString;
for (int i = 0; i < returnParams.Count; i++)
{ string nextKey = returnParams.AllKeys
;
if (nextKey == "result")
res = returnParams
;
else if (nextKey == "id")
userid = returnParams
;
}
if (res != "Accepted")
{ if (res == "Declined")
{ Label_Result.Text = "[" + res + "]" + " --> Declined";
}
else if (res == "NoPrivacyUrl")
{ Label_Result.Text = "[" + res + "]" + " --> No Privacy URL supplied";
}
}
else if ((res == "Accepted") && (userid != null))
{ Session["Result"] = res;
Session["Id"] = userid;
Label_Result.Text = "Result: " + res + ", User ID: " + userid;
string scriptTmplt = "http://messenger.services.live.com/users/{0}/{1}/?{2}"; string scriptUrl = string.Format(scriptTmplt, userid, "presence", "cb=showpresence");
string script = "<script type=\"text/javascript\" language=\"javascript\" src=\"" +
scriptUrl + "\"></script>";
ClientScript.RegisterStartupScript(typeof(showmypresence), "msgScript", script);
}
}
}
5. Create privacy.html file, something like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Page</title>
</head>
<body>
Your primacy is safe..
</body>
</html>
Now, your presence status can be displayed using URL:
http://localhost:50000/MessengerPresence/showmypresence.aspx?
result=Accepted&id=cbe0e395b6f9491@apps.messenger.live.com
Tips:
At web site property, set use dynamic port to false and set static port:
That's it. Have a nice try.
Look at the attachment for complete source code.
These are the photos of the day...
Sorry Ben...just kidding..no intention to harm you :) You're a good trainer. Wish the topics can be deeper.
"Pak Camat" & Ben William :)
The great foods. Serem amat bos Ris...
Naren explores the city...Are looking at "lady boy" ren? :P