How to display your MSN Messenger contact on site

xiaoxiao2021-03-06  68

Put Messenger Contacts on Your Site Heath Stewart (Clubstew@hotmail.com)

A thread here at DevHood started back on Monday, June 10, 2002, about getting the status of users in your MSN / Windows Messenger ( "Messenger" from now on) list and displaying it on your web site. If you take a quick peek , there were a lot of questions about such a feat. As I researched the problem, I thought this would warrant a tutorial since it's a great way to enhance your site with Messenger. This tutorial will help you understand a little about the Messenger API's and will help you put a Messenger Buddy List on your site. Once finished, you should be able to understand the API's and extend the features, such as putting images next to a pre-existing list of users, perhaps from a database, for those that . have Messenger and associated Passports What you'll Need Before we get started, you'll want to download one or two things Even though the web page uses client-side scripting to display (or harness) a Messenger contact list -. which requires The end-user to have messenger - you'll Want Messenger Too in Order to Test IT (if You Don't Already). If You're Not Using MSN Messenger (PRE-Windows XP) OR WindowsMessenger (Windows XP), You'RE Missing Out. Packed with Features and A Low Footprint On Your System, You May Download It At http://mesenger.msn.com/.you'll Also Benefit from the Messenger API Documents (chm - or compiled html help - files), Which you can get from http: / /messenger.msn.com/for_developers/default.asp. If you havea newer version of Messenger, you already have the automation interfaces registered on your system. Introduction to the Messenger API's The Messenger API is a very rich API (unlike AOL IM, WHO WON '

t let anyone touch their precious protocol), but can be a little confusing. There is an automation interface for controlling the user interface, an automation interface for writing plugins, and an automation interfacefor services extensions (like the Exchange service plugin for Messenger). The one we're interested in today is the user interfaceautomation library. If you're using VC , you'll want to take a look at the MessengerUI.chm file, especially the documentation for VC describing all the interfaces and UUIDs. If you're a VB programmer or .NET developer, you'll want to take a look at the section for VB. It describes everything using objects, enumerations, and still gives you the juicy stuff. Writing a Simple Macro with the Messenger API 'Sfor A SIMPLE TEST, I ADDED A Reference To The "Messenger API TYPE LIBRARY" in Excel's VBA Environment, And Made this Quick Little Macro: Public Sub getBuddies ()

DIM MSGR AS New MessengeRapi.Messenger

Dim Groups as IMessengergroups

DIM Group As IMessengergroup

Dim Contacts as ImessengerContacts

DIM Contact As IMessengerContact

DIM I as integer

DIM J AS INTEGER

I = 1

J = 1

Set groups = msgr.mygroups

For Each Group in Groups

Sheet1.cells (i, 1) = group.name

SET Contacts = Group.Contacts

J = i 1

For Each Contact in Contacts

Sheet1.cells (J, 2) = Contact.FriendlyName

Sheet1.cells (j, 3) = contact.signinname

Sheet1.cells (J, 4) = getStatus (Contact.Status)

J = J 1

NEXT

I = j

NEXT

End Sub

Public Function GetStatus (I as integer) AS String

Dim Str As String

SELECT CASE I

Case 1

Str = "offline"

Case 2

Str = "Online"

Case 6

Str = "invisible" case 10

Str = "busy"

Case 14

Str = "be right back"

Case 18

Str = "iDLE"

Case 34

Str = "away"

Case 50

Str = "on the phone"

Case 66

Str = "Out to Lunch"

Case Else

Str = "unknown"

End SELECT

GetStatus = STR

END FUNCTION

With command-completion, this was a breeze. If you try taking the same approach with a scripting language like JScript (Microsoft's JavaScript) or VBScript, you'll find that it does not work. Even if you use "var msgr = new ActiveXObject (...) "for jscript or" set msgr = creteObject (...) "for vbscript, you'll get a scripting error from Internet Explorer (IE) That States It Can't create the Automation Object.so What gives? Beats me. I use the delightful and extremely helpful OLEView.exe utility that comes with every free and commercial development environment Microsoft distributes to look at all the automation interfaces, coclasses, and type library information and wound up just scratching my head. While Visual Basic can use the ProgID to create an instance of the coclass (class that implements the interface to which you think you're talking) and Visual C can use the CLSID, you can use neither in your scripting environment because the ProgIDs do not Actually Create Objects in That INSTA nce. If you can figure this one out, by all means email me! There is hope, however. If you dig around in Hotmail's source, you'll find a reference to a JavaScript file (.js) that contains all the goodies. Microsoft uses the infamous tag to instantiate the object.Writing a Simple Script with the Messenger API'sSo, lets create a simple HTML page with some basic functionality to display your name:

Messenger Contact List</p> <p>Title></p> <p><script language = "jscript" Event = "onload" for = "window"></p> <p>IF ("undefined"! = TypeOf (msgrui))</p> <p>Document.all.welcome.innertext = msgrui.myfriendlyname "'s Messenger Contacts";</p> <p>Script></p> <p>HEAD></p> <p><body background = "white" text = "black"></p> <p><p> <b id = "welcome"> Messenger buddies</p> <p>B></p> <p>P></p> <p><p id = "msgrlist"> <ip = "msgrbuds" /></p> <p>P> <Object classid = "CLSID: B69003B3-C55E-4B48-836C-BC5946FC3B28" ID = "msgrui" width = "1" height = "1" style = "Display: none;" /></p> <p>Body></p> <p>HTML></p> <p>When you open this page, you get a scripting error that "MyFriendlyName" is not supported. You'll notice it's in the docs for the MessengerAPI.Messenger coclass that you instantiate (that's the CLSID for that ProgID in the <object /> tag). If you try the VC method of prepending "get_" to the property like "get_MyFriendlyName", you do not get an error but "undefined" is returned. In fact, as you'll find, "undefined" is returned for almost everything, including "MyContacts" and "MyGroups". Even though these properties are available in compiled languages ​​such as VC and VB, they are not available in scripting languages. I'm sure this is by design, it's just not documented. Do not give up hope, yet! Where there's a will, there's a way. Digging around in Hotmail's source a little more, I noticed a different set of CLSID's that they were using. Unfortunately, the one CLSID they were using was not documented In The Chm Files I Had You Download, Which Was for The Messenger.msgrobject Progid. OLE View.exe showed me the light once again, however, and I ended up using the CLSID's for both the Messenger.MsgrObject and Messenger.UIAutomation objects, the latter of which implements all the things that Visual Basic could use so easily.Writing a Advanced Script using the Messenger API'sWe will finally create a page that works. We will use two objects, one of which is undocumented, but is described thoroughly by OLEView.exe if you understand IDL (the "COM language"). We can ' T Rely on the Messenger.uiautomation Object Since IT Apparently Returns "undefined"</p> <p>when hosted in IE (or perhaps any scripting language). The other object (Messenger.MsgrObject) we will use does the trick, but it's by no means as elegant as Messenger.UIAutomation, which provides more functionality that actually does work in a scripting Environment.What Follows Is The Final Html for this Tutorial, And I'll Explain Certain Sections Briefly Below It: <HTML></p> <p><HEAD></p> <p><Title> Messenger Contact List</p> <p>Title></p> <p><script logage = "jscript"></p> <p>Script></p> <p><script language = "jscript" Event = "onload" for = "window"></p> <p>Script></p> <p>HEAD></p> <p><body background = "white" text = "black"></p> <p><p> <b id = "welcome"> Messenger Contacts</p> <p>B></p> <p>P> <p id = "msgrlist"> <ip = "msgrbuds"></p> <p>OL></p> <p>P> <object classid = "CLSID: F3A614DC-ABE0-11D2-A441-00C04F795683" ID = "msgr" width = "1" height = "Style =" Display: none; "/> <object classid =" CLSID : B69003B3-C55E-4B48-836C-BC5946FC3B28 "ID =" msgrui "width =" 1 "Height =" 1 "style =" Display: none; "/></p> <p>Body></p> <p>HTML></p> <p>As you can see, we now use two <object /> tags:. "Msgr" is the Messenger.MsgrObject object, and "msgrUI" is the Messenger.UIAutomation object Remember, if you try to instantiate these using "new ActiveXObject () "CreateObject ()", The Automation Interface Won't be Created. Also, Don n't Try This Server-Side, IT Will Just Use Your Messenger Contact List - IF IT Even Works (The Documentation Warns Against this, TOO) .You could add some browser detection code in there to keep Mozilla / Netscape from trying to do something it can not, but that should be taken care of by specifying the language as "JScript" instead of "JavaScript" (last time I checked , at least with 4.x) .The <script /> block that is attached to the "window.onload" event displays the list, or an error message depending on the state of you or your clients' Messenger. The regular <script /> block contacts helper functions and event handlers buy throughout the page.in the "window.onload ()" Event handler, we use the "msgr" Object and simply get your friendly name and the list of users. If you used "msgrUI", this would not work since "undefined" would be return for each. We then iterate through the list of users and display HTML appropriate for each one. In That Event Handler - At The Point WE Add HTML To Output - We Call Another Function, "SetLink ()". This method Outputs An "a.onclick" Event in the output html. When the user clicks the link for a name, IT Calls the "InstantMessage ()" Function.The "instantMessage ()" Function Uses the other object, "msgrui"</p> <p>. It contains a method (which actually works) that displays the Instant Messaging (chat) window with the specified user as the recipient.We also use the "AutoSignin ()" method of the "msgrUI" object in the "signIn ()" method we defined because it does not require user credentials (username and password). It tried to log in with the last-known credentials, just like Messenger does when it starts-up. The "msgr" object does have a "Login ( ) "method, but it requires a username and password, which you must prompt for and handle on your own. There could also be security hazards depending on your environment as well. If the" msgrUI "object can not automatically signin, it will prompt for credentials on its own, which is probably a more secure method than JScript or VBScript could provide.The rest of the code is pretty basic and self-explanitory, so I will not explain those.Extending Functionality: What Else You can DoThis Script Just Scratched The Surface of What You Can Do. as you can see from Hotmai l, they display an icon for each user that is in your list and that is online. If you wanted, you can create a bunch of icons (or tear them from the Messenger executable) to display next to users instead of their status as text Which is what i did in my latter sample "<img ...>" with the properties INSTEAD OF "OFFLINE", "Online", etc .if You're Displaying a Bunch of Users with email address A DATABASE ALREADY AND You Would LIKE TO Add An icon Next To Each As Described Above, You Could Write a Method That Would Search for the email address in the clients'</p> <p>Contact List and the place an icon next to each, such as the following: <script language = "jscript" Event = "onload" for = "window"></p> <p>Script></p> <p><table ...></p> <p><tr></p> <p><TD ID = "User@domain.tld"> ...</p> <p>TD></p> <p>Tr></p> <p><tr></p> <p><TD ID = "User@domain.tld"> ...</p> <p>TD></p> <p>Tr></p> <p><tr></p> <p><TD ID = "joe@company.com"> ...</p> <p>TD></p> <p>Tr> ...</p> <p>Table></p> <p>Explore the API and find out all the things you can do with Messenger to leverage greater functionality for your clients.SummaryThe Messenger API is an extensive API for of many objects, methods, properties, and events you can use in your compiled and interpreted applications. you have to treat them differently, however. Scripting languages ​​do not work with the same ProgIDs that you may use in VC , VB, or even .NET. with a little patience, OLEView.exe, and a little scripting experience, you can Greatly Enhance Your Site with Messenger!</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-119775.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="119775" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.032</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'gxALqMAMB4x7sRCgYx7y_2BJ3qrBNfIgIaFo8pf8wicPebFSt1saUc0lys0ux8HGPlTMPQtrlspRypD4yh6ALvEg_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>