2015-06-16 6 views
2

Я пытаюсь реализовать windows live логин, используя их API javascript. Я имею в виду this документации в качестве примера и используя следующий код:windows live login получить адрес электронной почты

WL.Event.subscribe("auth.login", onLogin); 
     WL.init({ 
      client_id: 'my client id', 
      redirect_uri: 'redirect uri', 
      scope: ["wl.signin", "wl.basic"], 
      response_type: "token" 
     }); 
     WL.ui({ 
      name: "signin", 
      element: "signin" 
     }); 
     function onLogin(session) { 
      if (!session.error) { 
       WL.api({ 
        path: "me", 
        method: "GET" 
       }).then(
        function (response) { 
         console.log(response); 
         document.getElementById("info").innerText = 
          "Hello, " + response.first_name + " " + response.last_name + "!"; 
        }, 
        function (responseFailed) { 
         document.getElementById("info").innerText = 
          "Error calling API: " + responseFailed.error.message; 
        } 
       ); 
      } 
      else { 
       document.getElementById("info").innerText = 
        "Error signing in: " + session.error_description; 
      } 
     } 

Приведенный выше код возвращает id, name и других областях, но я также хочу, чтобы получить пользователя email и profile picture url поля, как, как он возвращается в API google+, указав email в scope. Я прошел через WL.init documentation и не упоминается email и profile picture urlscope значения. Любой способ получить эти два поля?

ответ

0

Что касается областей взглянуть на https://msdn.microsoft.com/en-us/library/hh243646.aspx#core

Вам нужно «wl.emails» для сообщений электронной почты пользователя, «меня». Для изображения пользователя не нужны специальные рамки

var scope = {scope:["wl.signin", "wl.basic", "wl.emails"]}; 
WL.login(scope, windowsLiveLoginCallback); 

...

WL.api({ 
    path: "me", 
    method: "GET" 
}).then(
    function (response){ 
     var email = ""; 
     if(response.emails.preferred){ 
      email = response.emails.preferred; 
     } 
     else if(response.emails.account){ 
      email = response.emails.account; 
     } 
     WL.api({ 
      path: "me/picture", 
      method: "GET" 
     }).then(
      function(pictureResponse){ 
       // pictureResponse.location 
      }, 
      function (responseFailed){ 
       console.log('WL.api(me) error: ', responseFailed); 
      } 
     ); 
    }, 
    function (responseFailed){ 
     console.log('WL.api(me) error: ', responseFailed); 
    } 
); 
Смежные вопросы