从桌面应用程序访问联系人 [英] Accessing Contacts from desktop application

查看:101
本文介绍了从桌面应用程序访问联系人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从桌面应用程序访问livecontacts。广泛描述的是通过Web应用程序访问它们。它基于委托身份验证(http://msdn.microsoft.com/en-us/library/cc287637%28v=MSDN.10%29.aspx),其中一个
可以获取位置ID(盖子)需要访问livecontacts(http://msdn.microsoft.com/en-us/library/bb463989%28v=msdn.10%29.aspx)。还有  Live Client API及其身份验证(获取cId)和GetTicket函数。但如何使用它来访问
直播联系人?有人可以提供帮助吗?

I would like to access livecontacts from my desktop application. What is widely described is accessing them via web application. It is based on delegated authentication(http://msdn.microsoft.com/en-us/library/cc287637%28v=MSDN.10%29.aspx), with which one can get location id(lid) needed to access livecontacts(http://msdn.microsoft.com/en-us/library/bb463989%28v=msdn.10%29.aspx). There is also  Live Client API with its authentication (obtaining cId) and GetTicket function. But how to use this to access live contacts? Anyone could help?

我的代码无效(错误401)如下:

My code which is not working (error 401) is following:

(Post.xml - 与SamplePost相同。来自msdn的xml示例-http://msdn.microsoft.com/en-us/library/bb463974%28v=MSDN.10%29.aspx)

(Post.xml - is the same as SamplePost.xml from msdn example-http://msdn.microsoft.com/en-us/library/bb463974%28v=MSDN.10%29.aspx)

public static void AddContact(Identity oId)

        {

            UriBuilder uriBuilder = new UriBuilder();

            uriBuilder.Scheme =" HTTPS";

            uriBuilder.Path =" / users / @ L @" + oId.cId +" / REST / LiveContacts / Contacts";

            uriBuilder.Host =" livecontacts.services.live.com"; $
            uriBuilder.Port = 443;

            string uriPath = uriBuilder.Uri.AbsoluteUri;
$




          ; 

         

            HttpWebRequest的请求=(HttpWebRequest的)HttpWebRequest.Create(uriPath);

            string ticket ="" ;;

            //获取联系人服务的票证。

           试试
            {

               //票= oId.GetTicket(QUOT; members.msn.com"," MBI" ;,真);

        &NBSP ;      票= oId.GetTicket(QUOT; livecontacts.services.live.com"," MBI" ;,真);

        &NBSP ;   }
            catch(WLLogOnException wlex)

            {

                //检查FlowUrl是否已定义。

               如果(wlex.FlowUrl!= NULL)

                {

                    //如果定义了FlowUrl,请将用户定向到网页以更正错误。

                     MessageBox.Show(wlex.ErrorString +"请转至" + wlex.FlowUrl.AbsoluteUri +"纠正导致错误的条件和QUOT;);

   &NBSP ;            }
               否则b $ b                {

                    //如果没有定义FlowUrl,简单地显示Errorstring,则

              &NBSP ;     MessageBox.Show(wlex.ErrorString);

                }
            }
           

            request.Headers.Add(" Authorization"," WLID1.0" + ticket);

             request.AllowAutoRedirect = false;

            request.UserAgent = QUOT; WindowLiveClientSDKSpacesLoginTester英寸;

            request.ContentType =" application / xml; charset = utf-8" ;;

            request.Pipelined = false;

            request.ProtocolVersion = HttpVersion.Version10;

            request.Method =" POST"; $


            // ---------------------

           ;  byte [] buff = null;

           的FileStream FS =新的FileStream(QUOT; Post.xml" ;, FileMode.Open,FileAccess.Read);

             BinaryReader br = new BinaryReader(fs);

            long numBytes = new FileInfo(" Post.xml")。Length;

            buff = br.ReadBytes((int)numBytes);

            // ---------------------



       ;     使用(Stream requestStream = request.GetRequestStream())

            {

             

                requestStream.Write(buff,0,(int)numBytes);

            }
            HttpWebResponse响应=(HttpWebResponse)request.GetResponse();

            MessageBox.Show(response.StatusCode.ToString()); 


        }

public static void AddContact( Identity oId)
        {
            UriBuilder uriBuilder = new UriBuilder();
            uriBuilder.Scheme = "HTTPS";
            uriBuilder.Path = "/users/@L@" + oId.cId + "/REST/LiveContacts/Contacts";
            uriBuilder.Host = "livecontacts.services.live.com";
            uriBuilder.Port = 443;
            string uriPath = uriBuilder.Uri.AbsoluteUri;


          
         
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uriPath);
            string ticket = "";
            //Get ticket for contacts service.
            try
            {
               // ticket = oId.GetTicket("members.msn.com", "MBI", true);
                ticket = oId.GetTicket("livecontacts.services.live.com", "MBI", true);
            }
            catch (WLLogOnException wlex)
            {
                //Check to see if FlowUrl is defined.
                if (wlex.FlowUrl != null)
                {
                    //If FlowUrl is defined, direct user to the web page to correct the error.
                    MessageBox.Show(wlex.ErrorString + "Please go to " + wlex.FlowUrl.AbsoluteUri + "to correct the condition that caused the error");
                }
                else
                {
                    //If FlowUrl is not defined, simply display the ErrorString.
                    MessageBox.Show(wlex.ErrorString);
                }
            }
           
            request.Headers.Add("Authorization", "WLID1.0 " + ticket);
            request.AllowAutoRedirect = false;
            request.UserAgent = "WindowLiveClientSDKSpacesLoginTester";
            request.ContentType = "application/xml; charset=utf-8";
            request.Pipelined = false;
            request.ProtocolVersion = HttpVersion.Version10;
            request.Method = "POST";

            //---------------------
            byte[] buff = null;
            FileStream fs = new FileStream("Post.xml", FileMode.Open, FileAccess.Read);
            BinaryReader br = new BinaryReader(fs);
            long numBytes = new FileInfo("Post.xml").Length;
            buff = br.ReadBytes((int)numBytes);
            //---------------------

            using (Stream requestStream = request.GetRequestStream())
            {
             
                requestStream.Write(buff, 0, (int)numBytes);
            }
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            MessageBox.Show(response.StatusCode.ToString()); 
        }

谢谢

wojtek

推荐答案

你好wojtek,

Hello wojtek,

您无法使用Windows Live ID Client SDK访问Windows Live Contacts API。 Windows Live Contacts API目前仅支持委托身份验证。

You cannot use the Windows Live ID Client SDK to access the Windows Live Contacts API. The Windows Live Contacts API only supports Delegated Authentication currently.


这篇关于从桌面应用程序访问联系人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆