Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
hello firends,
 
I need you help in importing hotmail contacts i have written the below code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WindowsLive;
using System.Net;
using System.Xml;
using System.IO;
using System.Web.Services;
public partial class Demo : System.Web.UI.Page
{
 
    const string Offers = "Contacts.View";
    const string AuthCookie = "delauthtoken";
    static WindowsLiveLogin wll = new WindowsLiveLogin(true);
    protected WindowsLiveLogin.ConsentToken Token;
    protected string ConsentUrl;
    protected void Page_Load(object sender, EventArgs e)
    {
        ConsentUrl = wll.GetConsentUrl(Offers);
        Session["wll"] = wll;
        if (Session["HotmailToken"] != null)
        {
            WindowsLiveLogin.ConsentToken token = wll.ProcessConsent(Request.Form);
            Token = wll.ProcessConsentToken((string)Session["HotmailToken"]);
            if (Token != null)
            {
                string lid = Token.LocationID;
                long llid = Int64.Parse(lid, System.Globalization.NumberStyles.HexNumber);
                string delegatedToken = Token.DelegationToken;
                string uri = "https://livecontacts.services.live.com/@L@" + lid + "/rest/LiveContacts/Contacts/";
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
                request.UserAgent = "Windows Live Data Interactive SDK";
                request.ContentType = "application/xml; charset=utf-8";
                request.Method = "GET";
                request.Headers.Add("Authorization", "DelegatedToken dt=\"" + delegatedToken + "\"");
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                XmlDocument contacts = new XmlDocument();
                contacts.LoadXml(new StreamReader(response.GetResponseStream()).ReadToEnd());
                List<string> emails = new List<string>();
 
                XmlNodeList nodeList = contacts.SelectNodes("//Email/Address");
                foreach (XmlNode node in nodeList)
                {
                    if (!String.IsNullOrEmpty(node.InnerText))
                    {
                        emails.Add(node.InnerText);
                    }
                }
                listView.DataSource = emails;
                listView.DataBind();
 
            }
        }
    }
 
    [WebMethod]
    public static string GetHotmailContacts()
    {
        return wll.GetConsentUrl(Offers);
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WindowsLive;
namespace ImportContacts
{
    public partial class GetDateFromHotmail : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            WindowsLiveLogin.ConsentToken token = ((WindowsLiveLogin)Session["wll"]).ProcessConsent(Request.Form);
            Session["HotmailToken"] = token.Token;
            Response.Redirect("http://pinny.com");
 
        }
    }
}
 

but i am getting an exception "abc.com is making an insecure request to access your information. Windows Live does not allow information to be shared with this type of request.”

 
so friends please help me.
Thanx in advance
Posted 25-Dec-12 21:37pm
amit 7467
Edited 25-Dec-12 21:45pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Please refer: Creating and reading Hotmail contacts (Live Connect)[^]- This topic describes how your apps can use the Live Connect APIs to create and read a Hotmail user's contacts.
 
Here are few test I found here[^] which you need to do before importing contacts from hotmail; have a look
1. Register your application to get Client ID and Client Secret
http://go.microsoft.com/fwlink/?LinkID=144070[^]
2. Download and install Windows Live ID Delegated Authentication SDK 1.2
http://www.microsoft.com/download/en/details.aspx?id=2860[^]
3. Add file windowsLiveLogin.cs to Project. It should be in
C:\Program Files\Windows Live ID\DelAuth\App_Code
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web04 | 2.8.1411022.1 | Last Updated 26 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100