├── Episode 0.gs ├── Episode 1.gs ├── Episode 2.1 ├── Episode 2.gs ├── README.md ├── index.html └── index_css.html /Episode 0.gs: -------------------------------------------------------------------------------- 1 | function myFunction() { 2 | UrlFetchApp.fetch(url) 3 | } 4 | -------------------------------------------------------------------------------- /Episode 1.gs: -------------------------------------------------------------------------------- 1 | function myFunction() { 2 | let data = { 3 | 'name': 'Courtney Tat', 4 | 'email': 'courtneythetat@gmail.com', 5 | }; 6 | 7 | const params = { 8 | 'method': 'POST', 9 | 'contentType': 'application/json', 10 | 'payload': JSON.stringify(data) 11 | } 12 | 13 | let res = UrlFetchApp.fetch('https://script.google.com/macros/s/AKfycbyTSffReC0YmU5MbK7J_AVZBWyCBtAGhaX0KF5qzcJqCis4Iaf3/exec', params) 14 | // let res = UrlFetchApp.fetch('https://developers.google.com/apps-script/reference/url-fetch'); 15 | // let res = UrlFetchApp.getRequest('https://script.google.com/macros/s/AKfycbyTSffReC0YmU5MbK7J_AVZBWyCBtAGhaX0KF5qzcJqCis4Iaf3/exec', params) 16 | Logger.log(res); 17 | } 18 | 19 | // You can host your Apps Script Website from this project or an entirely separate project 20 | function doGet() { 21 | return HtmlService.createTemplateFromFile('index').evaluate() 22 | .setTitle('Early Access List') 23 | .setFaviconUrl('https://www.publicdomainpictures.net/pictures/310000/nahled/purple-circle.png'); 24 | } 25 | 26 | function doPost(e) { 27 | let data = e.parameter; 28 | 29 | SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/1qAIEhpYHfVLQ1BwOGb4vBe8QJGyeEkcREZxsEJnINaI/edit#gid=0') 30 | .appendRow([data.name, data.email]); 31 | 32 | return ContentService.createTextOutput("Post Complete"); 33 | } 34 | 35 | function includeExternalFile(filename) { 36 | return HtmlService.createHtmlOutputFromFile(filename).getContent(); 37 | } 38 | -------------------------------------------------------------------------------- /Episode 2.1: -------------------------------------------------------------------------------- 1 | $clientId = "your application ID goes here" 2 | 3 | Start-Process "https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=$clientId&scope=files.read offline_access&response_type=code&redirect_uri=https://login.live.com/oauth20_desktop.srf" 4 | 5 | $code = Read-Host "Please enter the code" 6 | 7 | $response = Invoke-WebRequest https://login.microsoftonline.com/common/oauth2/v2.0/token -ContentType application/x-www-form-urlencoded -Method POST -Body "client_id=$clientid&redirect_uri=https://login.live.com/oauth20_desktop.srf&code=$code&grant_type=authorization_code" 8 | 9 | Write-Output "Refresh token: " ($response.Content | ConvertFrom-Json).refresh_token 10 | -------------------------------------------------------------------------------- /Episode 2.gs: -------------------------------------------------------------------------------- 1 | function main() { 2 | // const clientId = "{yourclientid}"; 3 | // const refreshToken = "{yourrefreshtoken}"; 4 | 5 | let data = { 6 | 'client_id': clientId, 7 | 'refresh_token': refreshToken, 8 | 'redirect_uri': 'https://login.live.com/oauth20_desktop.srf', 9 | 'grant_type': 'refresh_token' 10 | }; 11 | 12 | let params = { 13 | 'method': 'post', 14 | 'contentType': 'application/x-www-form-urlencoded', 15 | 'payload': data, 16 | }; 17 | 18 | let res = UrlFetchApp.fetch('https://login.microsoftonline.com/common/oauth2/v2.0/token', params); 19 | 20 | const tokens = JSON.parse(res.getContentText()); 21 | console.log(tokens['access_token']); 22 | params = { 23 | headers: { 24 | Authorization: `Bearer ${tokens['access_token']}` 25 | }, 26 | }; 27 | 28 | res = UrlFetchApp.fetch("https://graph.microsoft.com/v1.0/me/drive/root:/Incoming_Candidates.xlsx:/workbook/worksheets/Sheet1/range(address='A1:B4')", params); 29 | if (res.getResponseCode().toString().startsWith('2')) { 30 | const json = JSON.parse(res.getContentText()); 31 | let values = json.values; 32 | SpreadsheetApp.openById('1qAIEhpYHfVLQ1BwOGb4vBe8QJGyeEkcREZxsEJnINaI').getSheetByName('Sheet2').getRange('A1:B4').setValues(values); 33 | } else { 34 | console.error() 35 | } 36 | 37 | const resp = UrlFetchApp.fetch('https://cdn.worldvectorlogo.com/logos/onedrive-1.svg'); 38 | let content = resp.getContent() 39 | let blob = Utilities.newBlob(content) 40 | DriveApp.createFile(blob) 41 | 42 | } 43 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Apps-Script-Season-11-URL-Fetch-Service 2 | The source code used in season 11 of my Apps Script Youtube channel (https://www.youtube.com/playlist?list=PL42xwJRIG3xDormBAHLcxorCYpHlHa_IE) 3 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 |

Get Early Access to my Website!

12 |
13 | 14 |

15 | 16 |

17 | 18 |
19 |
20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /index_css.html: -------------------------------------------------------------------------------- 1 | 48 | --------------------------------------------------------------------------------