Getting status from window live presence api in interval of 2mins

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gagonm
    New Member
    • Oct 2007
    • 26

    Getting status from window live presence api in interval of 2mins

    Hi All
    I have a scenario where I need to call windows live presence api in interval of 2 to continuously update presence status of an user on my webpage without postback.I went through this link, I just want whatever is mentioned here but top on that ability to call this API after regular interval
    http://msdn.microsoft. com/en-us/library/bb936689.aspx




    Thanks
    Jalaj
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Use window.setinter val().

    Comment

    • gagonm
      New Member
      • Oct 2007
      • 26

      #3
      Hi
      I am bit new to javascript.

      Also I m calling a link which is in altogether different domain.So I don't know how
      to achieve this. Anycode sample would be of great help

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Have you managed to get any information back while using the API? Can you show the code that you've tried so far.

        Comment

        • gagonm
          New Member
          • Oct 2007
          • 26

          #5
          Originally posted by acoder
          Have you managed to get any information back while using the API? Can you show the code that you've tried so far.
          Code:
          <!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>   
             <div id="innerFrame"></div>
             
             <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;
                statusIcon.width = presence.icon.width;
                statusIcon.height = presence.icon.height;
                statusIcon.alt = presence.statusText;
                statusIcon.title = presence.statusText;
          
                var displayName = document.createElement('span');
                displayName.style.fontFamily = 'Tahoma, Verdana, sans-serif';
                displayName.style.fontSize = '9pt';
                displayName.title = presence.displayName;
                
                var statusText = document.createElement('span');
                statusText.style.fontFamily = 'Tahoma, Verdana, sans-serif';
                statusText.style.fontSize = '9pt';
                statusText.title = presence.statusText;
                
                var br = document.createElement('br');
                
                innerFrame.appendChild(statusIcon);
                innerFrame.appendChild(br);
                innerFrame.appendChild(displayName);
                innerFrame.appendChild(br);
                innerFrame.appendChild(statusText);
                
                if ((displayName.innerText !== undefined)&&(statusText.innerText !== undefined))
                {
                   displayName.innerText = presence.displayName;
                   statusText.innerText = presence.statusText;
                }
                else if ((displayName.textContent != undefined)&&(statusText.textContent !== undefined))
                {
                   displayName.textContent == presence.displayName;
                   statusText.textContent == presence.statusText;
                }
             }
             </script>
             <script type="text/javascript" language="javascript"
          src="http://messenger.services.live.com/users/670D6EA19275AD0B@apps.messenger.live.com/presence/?cb=showpresence">
             </script>
            
              <p>
                  
          </body>
          </html>
          This is the version of code which is also there at msdn
          http://msdn.microsoft. com/en-us/library/bb936688.aspx

          Now this code gets users presence .I want to get user's presence status in interval of 2 mins without refreshing my page.

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            The script just returns a function call, so you need to put that in a function and call it every two minutes, e.g.:
            [code=javascript]function showNew() {
            var script = document.create Element("script ");
            script.type="te xt/javascript";
            script.src="htt p://messenger.servi ces.live.com/users/670D6EA19275AD0 B@apps.messenge r.live.com/presence/?cb=showpresenc e";
            document.body.a ppendChild(scri pt);
            }[/code]Call showNew() using setInterval every 120 seconds.

            Comment

            • gagonm
              New Member
              • Oct 2007
              • 26

              #7
              Thanks a ton .That's what I wanted .
              Only One question more
              creating script element again will create any issue??

              when I went to see the size of Iexplore.exe which was running this particular code,its size was continuosly increasing. AnyOther solution would be fine,otherwise this will also do
              Last edited by gagonm; Aug 21 '08, 05:42 PM. Reason: adding more info

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                Give the script tag an ID and then try setting its src. If not that, then try replacing the script and see if that makes a difference.

                Comment

                • gagonm
                  New Member
                  • Oct 2007
                  • 26

                  #9
                  It worked :)
                  Thanks again

                  Comment

                  • acoder
                    Recognized Expert MVP
                    • Nov 2006
                    • 16032

                    #10
                    You're welcome. Glad it's working.

                    Comment

                    Working...