windows live登录获取电子邮件地址

时间:2015-06-16 10:32:36

标签: javascript jquery asp.net email windows-live

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

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和其他字段,但我还希望获得用户的emailprofile picture url字段,例如google+email字段1}} API,在scope中提及email。我已完成WL.init documentation,但未提及profile picture urlscope SQL> conn / as sysdba Connected. SQL> create table test (id number(10), v_char varchar2(10)); Table created. SQL> insert into test values(11111111111,'darshan'); insert into test values(11111111111,'darshan') * ERROR at line 1: ORA-01438: value larger than specified precision allows for this column SQL> insert into test values(11111,'darshandarsh'); insert into test values(11111,'darshandarsh') * ERROR at line 1: ORA-12899: value too large for column "SYS"."TEST"."V_CHAR" (actual: 12, maximum: 10) SQL> insert into test values(111,'Darshan'); 1 row created. SQL> 值。有没有办法获得这两个领域?

1 个答案:

答案 0 :(得分: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);
    }
);