Click here to Skip to main content
16,016,180 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello firends,

I need you help in importing hotmail contacts i have written the below code:

C#
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);
    }
}

C#
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
Updated 25-Dec-12 20:45pm
v2

 
Share this answer
 
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
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900