3

我正在尝试windows live使用他们的 javascript API 实现登录。我将此文档作为示例并使用以下代码:

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,但我也想通过在. 我浏览了WL.init 文档,并没有提到和值。有什么办法可以得到这两个字段?emailprofile picture urlgoogle+emailscopeemailprofile picture url scope

4

1 回答 1

1

关于范围,请查看 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);
    }
);
于 2015-11-18T13:54:02.167 回答