繁体   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