- PlusDomainUtils.js
- getProfile(userId) - Retreive Google+ Profile for the given userId.
- getPicUrl(userId) - Return simple url to Google+ profile picture for the given user.
- test_getPicUrl() - test harness
- getPathFromUrl(url) - strip query string to return bare URL
Created
July 17, 2014 04:31
-
-
Save mogsdad/abb0e081f48552e02565 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Standard Google+ blank picture / no photo fill-in | |
var BLANK_PIC = 'https://lh3.googleusercontent.com/--ZclCWO7hZw/AAAAAAAAAAI/AAAAAAAAAAA/DXbpvdKqXVE/s100-c-k-no/photo.jpg'; | |
/** | |
* Retreive Google+ Profile for the given userId. | |
* | |
* @param {String} userId Google+ user id | |
* | |
* @return {Person} https://developers.google.com/+/domains/api/people#resource | |
*/ | |
function getProfile(userId) { | |
try { | |
var profile = PlusDomains.People.get(userId); | |
} catch (e) { | |
// If person not found in Google+, fake them | |
Logger.log(JSON.stringify(e)); | |
var profile = { id: 'unknown', | |
displayName : 'Not in Google+', | |
image: { url: BLANK_PIC }, | |
url: 'unknown', | |
error: e.message | |
} | |
} | |
// Logger.log('ID: %s', profile.id); | |
// Logger.log('Display name: %s', profile.displayName); | |
// Logger.log('Image URL: %s', profile.image.url); | |
// Logger.log('Profile URL: %s', profile.url); | |
// Logger.log(JSON.stringify(profile)); | |
return profile; | |
} | |
/** | |
* Return simple url to Google+ profile picture for the given user. | |
* | |
* @param {String} userId Google+ user id | |
* | |
* @return {String} picture url | |
*/ | |
function getPicUrl(userId) { | |
var profile = getProfile(userId); | |
return getPathFromUrl(profile.image.url); | |
} | |
/** | |
* Test harness for getPicUrl function | |
*/ | |
function test_getPicUrl() { | |
//var userId = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Form Responses").getRange("B2").getValue(); | |
var userId = '[email protected]'; | |
var picUrl = getPicUrl(userId); | |
debugger; | |
} | |
function getPathFromUrl(url) { | |
return url.split("?")[0]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment