Skip to content

Instantly share code, notes, and snippets.

@jz5
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jz5/6e960486050850c7e00d to your computer and use it in GitHub Desktop.
Save jz5/6e960486050850c7e00d to your computer and use it in GitHub Desktop.
<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