How do I import the Hotmail / Outlook contact list? [closed]

0

I recently had to import the Hotmail / Outlook mailing list from the users of my application, and here's one of the ways you can proceed if you also need to implement this feature on your front-end system, via JavaScript.

    
asked by anonymous 01.02.2016 / 17:33

1 answer

0

Step 1. Create a Windows Live application in the "Microsoft account Developer Center" to get your Client ID and Client Secret

Access the Microsoft account Developer Center page and create a new application by clicking on the "Create Application" link.

EnterthenameandlanguageyouwanttogiveyourapplicationandclickontheIAcceptbuttontoindicatethatyouhavereadandagreetoMicrosoft'stermsofuseforcreatingapplications.p>

UnderBasicInformationprovidetheotherbasicinformationofyourapplication,suchasthelogoimageandURLsofthetermsofserviceandusagepolicyofyourapplication.

OntheAPISettingstab,fillinthefieldsasfollows:

  • Mobileordesktopclientapp:No
  • Targetdomain:leaveblank
  • RestrictJWTissuing:No
  • Rootdomain:thisfieldwillpopulateautomaticallywhenyouenterthenextfield.
  • RedirectURLs:enterheretheURLofthepagetowhichWindowsLivewillredirectitsusersaftertheyconfirmthattheywishtoallowtheirapplicationtoaccesstheirmailinglist.

Placethefollowingcodeonyourredirectpage(inthecaseoftheexample,itwouldbethepagewww.mysite.com/redirection.html):

<!DOCTYPEHTMLPUBLIC"-//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>Página de Redirecionamento</title>
    </head>
    <body>
        <!-- Este script irá repassar a resposta de autorização oauth para a página que fez a solicitação de obtenção da lista de contatos. -->
        <script src="//js.live.net/v5.0/wl.js" type="text/javascript" language="javascript"></script>
    </body>
</html>

Access the App Settings tab to view the credentials (Client ID and Client Secret) that your application should use to connect to the Windows Live API, which will be our next step.

Step2.ExampleofanE-mailContactListImportCode

ImporttheWindowsLivelibraryintothepagewhereyouwanttoimportyouruser'semailcontactlist,asfollows:

<scriptsrc="//js.live.net/v5.0/wl.js"></script>

Initialize the Live JavaScript SDK by running the following code and replacing the values of client_id and redirect_uri with the values of your own application:

WL.init({
    client_id: 'CLIENT_ID_DE_SEU_APLICATIVO',
    redirect_uri: 'www.meusite.com.br/redirecionamento.html',
    scope: ["wl.basic", "wl.contacts_emails"],
    response_type: "token"
});

Create a button to perform the import of the contacts:

<input type="button" onclick="importeContatosDoHotmail();" value="Importar Contatos" />

Implement the Hotmail / Outlook contacts import function as in the following code:

function importeContatosDoHotmail() {
    WL.login({
        scope: ["wl.basic", "wl.contacts_emails"]
    }).then(function (response) {
        WL.api({
            path: "me",
            method: "GET"
        }).then(function (responseMe) {
            // Dados do perfil do usuário.
            console.log(responseMe);

            WL.api({
                 path: "me/contacts",
                 method: "GET"
            }).then(function (responseMeContacts) {
                // Lista de contatos de emails do usuário.
                console.log(responseMeContacts.data);
            },
            function (responseFailed) {
                // Motivo da falha de obtenção da lista de contatos do usuário.
                console.log(responseFailed);
                }
            );
        },
        function (responseFailed) {
            // Motivo da falha de obtenção dos dados do perfil do usuário.
            console.log(responseFailed);
        }
    );
 },
 function (responseFailed) {
    // Motivo da falha de autenticação com o Windows Live.
    console.log(responseFailed);
 });

}

    
01.02.2016 / 17:33