How to import mailing list from Hotmail/Outlook?

Asked

Viewed 331 times

0

Recently I had to import the Hotmail/Outlook mailing list of the users of my application, and I present below one of the ways you can proceed if you also need to implement this feature in your client-side system (Frontend) via Javascript.

1 answer

0


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

Go to the page Microsoft Account Developer Center and create a new application by clicking on the "Create Application".

Criando um novo aplicativo Windows Live

Enter the name and language you want to give to your app and click the button I Accept to indicate that you have read and agree to Microsoft’s terms of use for creating applications.

inserir a descrição da imagem aqui

In Basic Information provide the other basic information of your application, such as the logo image and Urls of your application’s terms of service and usage policy.

inserir a descrição da imagem aqui

On the tab API Settings, fill in the fields as follows:

  • Mobile or desktop client app: In the
  • Target Domain: leave blank
  • Restrict JWT issuing: In the
  • Root Domain: this field will be filled automatically when you enter the next field.
  • Redirect Urls: enter here the URL of the page to which Windows Live will redirect its users after they confirm that they wish to allow their application to access their email contact list.

inserir a descrição da imagem aqui

Put the following code on your redirect page (in the case of the example, it would be the www.meusite.com.br/redirect.html page):

<!DOCTYPE HTML PUBLIC "-//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>

Go to the tab App Settings 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.

inserir a descrição da imagem aqui

Step 2. Example Email Contact List Import Code

Import the Windows Live library to the page where you want to import your user’s email contact list, as follows:

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

Initialize the Live Javascript SDK by running the code below and overriding 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 import contacts:

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

Implement the import function of Hotmail/Outlook contacts 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);
 });

}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.