簡體   English   中英

Windows Live登錄獲取電子郵件地址

[英]windows live login get email address

我正在嘗試使用其JavaScript API實現windows live登錄。 我以文檔為例,並使用以下代碼:

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;
            }
        }

上面的代碼返回了idname和其他字段,但我也想通過在scope提及email來獲取用戶的emailprofile picture url字段,例如在google+ API中如何返回。 我已經遍歷WL.init文檔 ,沒有提到emailprofile picture url scope值。 有什么辦法可以得到這兩個領域?

關於范圍, 請參閱https://msdn.microsoft.com/zh-cn/library/hh243646.aspx#core

您需要“ wl.emails”作為用戶“ me”的電子郵件。 對於用戶的圖片,您不需要特殊的范圍

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM