Skip to content

Instantly share code, notes, and snippets.

@jz5
Last active Aug 29, 2015
Embed
What would you like to do?
<script>
// (省略)
function onAuthenticated(token, authWindow) {
if (token) {
if (authWindow) {
removeLoginButton();
authWindow.close();
}
(function ($) {
// Upload an item to OneDrive from a URL
$.ajax({
url: 'https://api.onedrive.com/v1.0/drive/special/photos/children?access_token=' + token,
type: 'POST',
headers: {
'Prefer': 'respond-async',
'Content-Type': 'application/json'
},
dataType: 'json',
data: '{' +
'"@content.sourceUrl": "http://pronama.azurewebsites.net/wp-content/uploads/2015/02/20150206.jpg",' +
'"name": "20150206.jpg",' +
'"file": { }' +
'}',
}).done(function () {
// MEMO: unreachable (2015/3/14)
console.log("success");
}).fail(function (xhr, textStatus, errorThrown) {
console.log(xhr);
});
})(jQuery);
}
else {
alert("Error signing in");
}
}
// start the whole thing off by calling odauth() in non-click mode.
// if the user isn't logged in already, a sign-in link will appear
// for them to click.
odauth();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment