Windows Live SDK First App

傅自明
2023-12-01

Prerequisite:

1. you must create an application record for it by using the Live Connect application management site (https://manage.dev.live.com)

2. If you are creating a web application, you must specify the redirect domain so that the service knows where to return users after they sign in

Note: if you don't have domain, or you want to test at local, you can assign a virtual domain name to your localhost ( add "127.0.0.1www.yourdomain.com" to "hosts" file under C:\Windows\System32\drivers\etc). Don't use any real domain name like google.com or your own domain name if you have any. If you did so, you cannot access the original remote site. This is because, 127.0.0.1 is loopback address, anything with that address will never leave your computer. 


Create a testing page via JS:

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="WindowsLiveSDKLearning._Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<script src="https://js.live.net/v5.0/wl.js" type="text/javascript"></script>
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript">

    $(document).ready(function () {
        WL.init({
            client_id: 'xxxxxxx',
            redirect_uri: '/WindowsLiveSDKLearning/Default.aspx',
            response_type: "token"
        });
    });

    var scopesArr = ["wl.signin", "wl.emails"];
    function signUserIn() {
        WL.login({ scope: scopesArr });
    }

    function signUserOut() {
        WL.logout();
    }

    function getUserInformation() {
        WL.api(
        {
            path: "me",
            method: "GET"
        },
        function (response) {
            if (!response.error) {
                strGreeting = "Hi, " + response.first_name + ", your email address is " + response.emails.account + "!"
                alert(strGreeting);
            }
            else {
                alert(response.error.message);
            }
        });
    }

    
</script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <h2>
        Welcome to ASP.NET!
    </h2>
    <p>
        To learn more about ASP.NET visit <a href="http://www.asp.net" title="ASP.NET Website">www.asp.net</a>.
    </p>
    <p>
        You can also find <a href="http://go.microsoft.com/fwlink/?LinkID=152368&clcid=0x409"
            title="MSDN ASP.NET Docs">documentation on ASP.NET at MSDN</a>.
    </p>

    <input type="button" id="signin" value="signin" name="signin" οnclick="signUserIn()"/>
    <input type="button" id="signOutButton" value="signout" οnclick="signUserOut()" />
    <input type="button" id="getUser" value="Get User Information" οnclick="getUserInformation()" />

</asp:Content>

OR

Create a testing page via .Net Code:

By using OAuth WRAP to acquire user consent and access data from a Windows Live service, your application follows these steps:

  1. Creating a verification code.
  2. Creating an access token request.
  3. Creating a refresh token request.
  4. Getting user data.

Reference

  1. Windows Live SDK JavaScript API:http://msdn.microsoft.com/en-us/library/hh243643.aspx
  2. Windows Live SDK Functionality: http://msdn.microsoft.com/en-us/library/hh243648.aspx#user

 类似资料:

相关阅读

相关文章

相关问答