2012-07-23 2 views

답변

1

대리인 인증을 사용하여 이메일을받을 수 있습니다. 내가 한 코드 스 니펫은 다음과 같습니다.

여기

public partial class DefaultPage : System.Web.UI.Page 
{ 
    //Comma-delimited list of offers to be used. 
    const string Offers = "Contacts.View"; 
    //Name of cookie to use to cache the consent token. 
    const string AuthCookie = "delauthtoken"; 

    // Initialize the WindowsLiveLogin module. 
    static WindowsLiveLogin wll = new WindowsLiveLogin(true); 

    protected WindowsLiveLogin.ConsentToken Token; 

    protected string ConsentUrl; 

    protected void Page_Load(object sender, EventArgs e) 
    { 
     //Get the consent URL for the specified offers. 
     ConsentUrl = wll.GetConsentUrl(Offers); 

     HttpRequest req = HttpContext.Current.Request; 
     HttpCookie authCookie = req.Cookies[AuthCookie]; 

     // If the raw consent token has been cached in a site cookie, attempt to 
     // process it and extract the consent token. 
     if (authCookie != null) 
     { 
      string t = authCookie.Value; 
      Token = wll.ProcessConsentToken(t); 
      getContacts(Token.DelegationToken,Token.LocationID); 
      if ((Token != null) && !Token.IsValid()) 
      { 
       Token = null; 
      } 
     } 
    } 

    private void getContacts(string token, string lId) 
    { 
     long intlid = Int64.Parse(lId, System.Globalization.NumberStyles.HexNumber); 
     HttpWebRequest request = (HttpWebRequest)WebRequest.Create(string.Format("https://livecontacts.services.live.com/users/@[email protected]{0}/rest/livecontacts/contacts/", intlid)); 
     request.UserAgent = "Windows Live Data Interactive SDK"; 
     request.ContentType = "application/xml; charset=utf-8"; 
     request.Method = "GET"; 
     request.Headers.Add("Authorization", "DelegatedToken dt=\"" + token + "\""); 

     using (WebResponse response = request.GetResponse()) 
     { 
      using (Stream stream = response.GetResponseStream()) 
      { 
       //docNav = new XPathDocument(stream); 
       StreamReader reader = new StreamReader(stream); 
       // var contactStreamReponse = reader.ReadToEnd(); 

       // XmlDocument contacts = new XmlDocument(); 
       // contacts.LoadXml(contactStreamReponse); 



       //Use the document. For example, display contacts.InnerXml. 

       // labelXml.Text = contacts.InnerXml; 

       if (CheckBoxList1.Items.Count < 1) 
       { 
        DataSet ds = new DataSet(); 
        ds.ReadXml(reader); 
        response.Close(); 
        if (ds.Tables["Contact"].Rows.Count > 0) 
        { 
         ArrayList al = new ArrayList(); 

         for (int intC = 0; intC < ds.Tables["Email"].Rows.Count; intC++) 
         { 
          //Response.Write("FOr instance" + intC); 

          //Response.Write(ds.Tables["Email"].Rows[intC]["Address"].ToString()); 
          ///Response.Write("<br>"); 
          al.Add(ds.Tables["Email"].Rows[intC]["Address"].ToString()); 
         } 
         CheckBoxList1.DataSource = al; 
         CheckBoxList1.DataBind(); 

        } 

       } 
       else 
       { 
        return; 
       } 
      } 


     } 
    } 
+0

안녕하세요 코드를 입력하고 SO에 오신 것을 환영합니다! 실제 설명이없는 링크를 게시하지 마십시오. 요약, 기사의 코드 스 니펫, 약간의 노력을 보여주는 것만 제공하십시오. 이 대답을 찾는 다른 사람을 도울 것입니다. =) –

관련 문제