Use SkyDrive to extend the "Windows 8" application to the cloud

Source: Internet
Author: User
Tags oauth sample html code

Although a person has multiple devices, many people still store all their important files on one PC or storage device, and cannot access these files from other devices. These files are associated with a location that can be a desktop PC, portable computer, or USB key. If you do not have access to this location, you will not be able to access your documents or photos. Not only is access to files very difficult (sometimes or even impossible), but sharing files with others on different networks is also tricky.

Now, the emergence of cloud allows people to access their content from almost any location (and very convenient !). Files are stored in a single location and can be accessed from any device connected to the internet anywhere in the world. By placing a single copy of a file in the cloud, it is easier to share photos and collaborate with documents in real time. However, the cloud has not yet become the mainstream usage of access content.

In the opening speech of the build conference, Chris Jones talked about how every Windows 8 client gets SkyDrive: everyone has a cloud where they can centrally store their important files, these files can be accessed and shared in real time. Some speeches at the Conference introduced how Windows 8 developers use live connect and live SDK for their applications.ProgramProvide cloud support. When applications are used with the cloud, Metro-style applications can use live cloud
Windows Live ID enables single logon and allows users to access personal data such as documents, photos, and videos on SkyDrive.

If you are considering developing a metro-style application for Windows 8, this blog will show you how to enable a single logon and access user data on SkyDrive, this makes your Metro-style applications more personalized-with the user's consent, of course.

Connect applications to the live cloud

As a developer, when you are preparing to build the next excellent application in the world, you will encounter two types of problems on any platform:

    • Enable the registration and logon functions for users.Users do not like to be forced to log on to websites and applications. Developers know that after a user logs on, their application participation and loyalty will increase. The logon feature allows you to customize user experience and enable your applications to remember user data and custom items.
    • It is easy to include user content into your applications to enhance your experience.When you consider that a user disperses his/her photos on a variety of devices and clouds, simple tasks such as setting profile pictures will instantly become complex.

In Windows 8, we solved these two problems for our own applications (such as "Photos" and "emails, your Metro-style applications can also use the same platform and technology. Specifically, we solve the above problems through the following methods:

    1. A user's cloud-based identity is now a basic element of the operating system. Applications and websites that obtain a user's single logon license can access this identity. This means that your application can inherit the login status of the user and its identity, so you do not have to worry about a separate authentication process. This is especially important for the implementation of method 2.
    2. We allow applications that use industry-standard protocols to access user content in the live cloud, including oauth for authentication and authorization, JSON is the payload of the data returned when you access SkyDrive and Hotmail, and XMPP is used to implement interoperability with Windows Live Messenger. In addition, we provide live sdks (integrated with Visual Studio 11 express) for Windows 8 developers to make winrt development easier.

After you connect your application to your Windows Live ID for the first time, this user will always have a seamless single logon experience on any Windows 8 PC that uses Windows Live ID. This applies to your website. If they use Windows Live ID to log on to their PC or any website that supports Windows Live ID (such as Hotmail or SkyDrive ), they will also have a single logon experience.

The easiest way to use Windows Live ID to log on with a single logon and integrate SkyDrive content into a metro-style application is to use the live SDK.

This does not mean that your application needs to use any of the services-whether or not to use them is entirely determined by the developer. Windows 8 applications are not required to use a live ID to log on or use any cloud-based storage. These are only services provided to application developers for their choice.

Use live SDK in applications

First, if you have not installed
Windows 8 Developer Preview and
Live SDK developers must install them first. This will also install Microsoft Visual Studio 11 express for Windows Developer Preview. Second, you need to access
Windows push notifications and live connect application management website to configure your Metro style application to access live cloud. Follow the steps on the website to register your application to use live connect.

After you configure the application to use live connect, you need to add a reference to the live SDK. The live SDK can be developed in C #, JavaScript, and VB languages. You can add a reference to your project by right-clicking the project and selecting "add reference"And [extension sdks] (Extended SDK)And then select the entry corresponding to the live SDK from the list, as shown below:

In JavaScript applications, you only need to add the following Script Reference to default.html:

 
<SCRIPT src ="Ms-wwa: // livesdkhtml.5.0/JS/WL. js"> </SCRIPT>

In C #, you must add the following referencesCodeUse the live SDK:

 
UsingMicrosoft. live;

In VB, you only need to use the following import statement:

 
ImportsMicrosoft. Live

This is just a good example of how we support programming in the selected language when building a Metro style application for Windows 8.

Use Windows Live ID in Metro style applications

To use the Single login (SSO) function in an application, you need to place a login button somewhere in the application. If the user has logged on to the PC using the Windows Live ID, the user will log on automatically when the user clicks the logon button; otherwise, the system will ask them to log on. Then, the user will be asked to allow your application to access their data, such as their SkyDrive photos. You only need to add the login button, and the system will automatically process this workflow for you. Please note that your customers still need to confirm whether to log on to your application, instead of logging on automatically. This is an important design consideration.

The following is the sample HTML code of the logon button (note that this is only a div and needs to be further configured ).

<Div ID= "Signinbutton" Style= "Width: 251px; margin-left: auto; margin-top: 40%; Height: 64px; top: 0px ;"> </Div>

After you add a logon button to the page, you must attach the button because all you have done in the example HTML is to allocate space for it on the page. We need to configure the logon button using the scope required by your application. ScopeDefine the content that the application has access to and that the user must agree to provide. To access SkyDrive data, your application must use the following two scopes:

    • WL. signin-This scope allows automatic logon to your application.
    • WL. SkyDrive-This scope grants users the permission to access your SkyDrive albums and photos (Note: if you plan to upload content to SkyDrive, your application should use
      WL. skydrive_update).

The following is an example of JavaScript code for initialization. Assume that you have created a logon button with the ID of "signinbutton" on the page:

FunctionInit () {WL. INIT (); WL. UI ({Name:"Signin", Element:"Signinbutton", Scope :["WL. signin","WL. SkyDrive"],});}

The following is the sample JavaScript code for processing Logon:

 
WL. event. subscribe ("Auth. login", Onlogincomplete );FunctionOnlogincomplete (){VaRSession = WL. getsession ();If(! Session. Error) {signedinuser ();}}

When a user clicks the login button, the system will ask for their consent to allow your application to access their data. As mentioned above, if you use a Windows Live ID to log on to the PC, a single logon will take effect, and you do not need to log on again. Instead, it will go directly to the request consent screen:

Access SkyDrive content from your application

After you grant the data access permission to your application, the system returns the oauth 2.0 access token to your application, then, the application can use these tokens to call the restful API of live cloud. The following is the JavaScript code used to access photos:

 
FunctionDownloadpicture (folderid ){VaRPath = folderid +"/Files"// Submit requestWL. API ({path: path, method:"Get"}, Onenumeratefoldercomplete )};

Through the above many calls, the app can embed SkyDrive content into its experience, such as PowerPoint slides, videos, Excel workbooks, or just some simple photos, as shown in the following example application.

As you can see, you only need to use the live SDK to compile several lines of code to integrate user data in a single logon and SkyDrive into an application. Your apps are more personalized and can take full advantage of user photos or documents in the cloud. Download the complete sample application shown in this blogSource code.

for more information about using the live SDK to enable single logon in the application and using the SkyDrive API, watch the speech of dare Obasanjo at the build conference and use the live Service to enhance the application function and Steve Gordon's speech
complete developer guide to SkyDrive API. For more information, visit the
http://dev.live.com and download the
live SDK Developer Preview.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.