Updated: GAS Library - OnedriveApp
-
v1.2.3 (March 11, 2024)
Modified the URL of the application installed in Microsoft Azure.
v1.2.3 (March 11, 2024)
Modified the URL of the application installed in Microsoft Azure.
v1.2.2 (July 27, 2023)
Checked the array of to, cc, and bcc for the sendEmails method.
v1.2.1 (July 26, 2023)
A bug of “Send Email messages” was removed.
This is a sample script for retrieving the list of all emails of Microsoft account and putting them to Google Spreadsheet using Google Apps Script.

I updated OnedriveApp to v1.2.0 by adding 1 method for retrieving the access token and 7 methods for managing emails of Microsoft account. By this, the emails got to be able to be gotten and sent using Microsoft account using OnedriveApp with Google Apps Script.
OnedriveApp was updated to v1.2.0.
v1.2.0 (October 4, 2021)
1 method for retrieving the access token and 7 methods for managing emails of Microsoft account were added. By this, the emails got to be able to be gotten and sent using Microsoft account using OnedriveApp with Google Apps Script.
OnedriveApp was updated to v1.1.2.
v1.1.2 (September 29, 2021)
A bug of method of uploadFile was removed. By this, the files except for Google Docs files can be uploaded to OneDrive.
OnedriveApp was updated to v1.1.1.
I have to apologize you and all users.
I had forgot that it added setProp(). I could notice about this by reporting at here.
I would like to report because I could remove this bug.
OnedriveApp was updated to v1.1.0.
From this version, retrieving access token and refresh token became more easy.

OnedriveApp was updated to v1.0.2.
OnedriveApp was updated to v1.0.1.
Added a method for retrieving access token and refresh token using this library.
By added this method, OneDrive APIs can be used by only this library.
This is a library of Google Apps Script for using Microsoft OneDrive.
This library can carry out following functions using OneDrive APIs.

You can see the detail information here https://github.com/tanaikech/OnedriveApp
In order to use this script, please retrieve client id, client secret and refresh token before. About this, you can see the detail information at https://gist.github.com/tanaikech/d9674f0ead7e3320c5e3184f5d1b05cc.
This is for the simple item upload is available for items with less than 4 MB of content. The detail information is https://dev.onedrive.com/items/upload_put.htm.
var fs = require('fs');
var mime = require('mime');
var request = require('request');
var file = './sample.zip'; // Filename you want to upload on your local PC
var onedrive_folder = 'SampleFolder'; // Folder name on OneDrive
var onedrive_filename = 'sample.zip'; // Filename on OneDrive
request.post({
url: 'https://login.microsoftonline.com/common/oauth2/v2.0/token',
form: {
redirect_uri: 'http://localhost/dashboard',
client_id: onedrive_client_id,
client_secret: onedrive_client_secret,
refresh_token: onedrive_refresh_token,
grant_type: 'refresh_token'
},
}, function(error, response, body) {
fs.readFile(file, function read(e, f) {
request.put({
url: 'https://graph.microsoft.com/v1.0/drive/root:/' + onedrive_folder + '/' + onedrive_filename + ':/content',
headers: {
'Authorization': "Bearer " + JSON.parse(body).access_token,
'Content-Type': mime.getType(file), // When you use old version, please modify this to "mime.lookup(file)",
},
body: f,
}, function(er, re, bo) {
console.log(bo);
});
});
});
This is for the resumable item upload is provided for large files or when a resumable transfer may be necessary. The detail information is https://dev.onedrive.com/items/upload_large_files.htm.
This GAS sample is for retrieving access token to use OneDrive APIs using Google Apps Script.
In this script, the authorization code is automatically retrieved.

In order to use this, both accounts of Google and OneDrive (MSN) are required.
https://script.google.com/macros/s/###/dev. So please modify this URL. Replace from “dev” to “usercallback” for the URL. And copy this modified URL.
https://script.google.com/macros/s/###/devhttps://script.google.com/macros/s/###/usercallbackhttps://script.google.com/macros/s/###/usercallbackBy above operation, the preparation is done.