Created
July 3, 2016 06:25
-
-
Save trevordixon/ef7bfd27cdba87402256ed078636c77d to your computer and use it in GitHub Desktop.
Make signed-in requests to LDS.org from Google Apps Scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function example() { | |
// This cookie is good for many subsequent requests (until it expires) | |
var cookie = getCookie('[username]', '[password]'); | |
var response = ldsGet(cookie, 'https://www.lds.org/mobiledirectory/services/v2/ldstools/current-user-detail'); | |
Logger.log(response.getContentText()); | |
} | |
function getCookie(username, password) { | |
var response = UrlFetchApp.fetch('https://signin.lds.org/login.html', { | |
method: 'post', | |
payload: {username: username, password: password}, | |
followRedirects: false, | |
}); | |
var cookieHeader = response.getAllHeaders()['Set-Cookie'][0]; | |
var cookie = decodeURIComponent(cookieHeader.match(/ObSSOCookie=([^;]+)/)[1]); | |
return cookie; | |
} | |
function ldsGet(cookie, url) { | |
return UrlFetchApp.fetch(url, { | |
headers: { | |
'Cookie': 'ObSSOCookie=' + encodeURIComponent(cookie), | |
}, | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks this helped me out quite a bit. I'm pulling in the member list into a spreadsheet.