I want to check whether a user is already logged in to OneDrive and, if not, allow them to log in. I first tried this with a JS/HTML project using the sample code provided by Microsoft here I added this code in the default.js file:
WL.init({ scope: ["wl.signin", "wl.skydrive"] }).then(
function (result) {
if (result.status == "connected") {
//display to the user, that they are connected
}
else {
// Display the sign-in button.
connectButton.style.display = "block";
connectButton.onclick = function () {
WL.login({
scope: ["wl.signin", "wl.skydrive"]
}).then(
function (result) {
if (result.status == "connected") {
// Don't display the sign-in button.
connectButton.style.display = "none";
//display to the user, that they are connected
}
}
);
};
}
});
and included this is the default.html header:
<script src="///LiveSDKHTML/js/wl.js"></script>
and this in the default.html body:
<button id="connectButton" style="display:none">
Connect with a Microsoft account</button>
However, after running the app, nothing seems to happen. I even changed the JavaScript to this just to make sure the function was being called correctly, but nothing happens. No background change (and yes I have jQuery included and it works outside the WL.init call):
WL.init({ scope: ["wl.signin", "wl.skydrive"] }).then(
function (result) {
if (result.status == "connected") {
$('body').css('background-clor', 'blue');
}
else {
$('body').css('background-clor', 'red');
}
});
After a while I looked at the C#/XAML OneDrive code here and it seemed easier to follow, so I created a project with that, only to get the error:
error CS0103: The name 'updateUI' does not exist in the current context
I would like to know how to make either method work (JS/HTML or C#/XAML).
Aucun commentaire:
Enregistrer un commentaire