-
Notifications
You must be signed in to change notification settings - Fork 2
/
Episode 2.gs
42 lines (35 loc) · 1.35 KB
/
Episode 2.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function main() {
// const clientId = "{yourclientid}";
// const refreshToken = "{yourrefreshtoken}";
let data = {
'client_id': clientId,
'refresh_token': refreshToken,
'redirect_uri': 'https://login.live.com/oauth20_desktop.srf',
'grant_type': 'refresh_token'
};
let params = {
'method': 'post',
'contentType': 'application/x-www-form-urlencoded',
'payload': data,
};
let res = UrlFetchApp.fetch('https://login.microsoftonline.com/common/oauth2/v2.0/token', params);
const tokens = JSON.parse(res.getContentText());
console.log(tokens['access_token']);
params = {
headers: {
Authorization: `Bearer ${tokens['access_token']}`
},
};
res = UrlFetchApp.fetch("https://graph.microsoft.com/v1.0/me/drive/root:/Incoming_Candidates.xlsx:/workbook/worksheets/Sheet1/range(address='A1:B4')", params);
if (res.getResponseCode().toString().startsWith('2')) {
const json = JSON.parse(res.getContentText());
let values = json.values;
SpreadsheetApp.openById('1qAIEhpYHfVLQ1BwOGb4vBe8QJGyeEkcREZxsEJnINaI').getSheetByName('Sheet2').getRange('A1:B4').setValues(values);
} else {
console.error()
}
const resp = UrlFetchApp.fetch('https://cdn.worldvectorlogo.com/logos/onedrive-1.svg');
let content = resp.getContent()
let blob = Utilities.newBlob(content)
DriveApp.createFile(blob)
}