Last active
September 8, 2022 00:45
-
-
Save printminion/5520613 to your computer and use it in GitHub Desktop.
Google Apps Script for getting Google+ ProfileId by url
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
/** | |
* @desc This is an Google Apps Script for getting Google+ ProfileId by url | |
* @author Misha M.-Kupriyanov https://plus.google.com/104512463398531242371/ | |
* @link https://gist.github.com/5520613 | |
*/ | |
function testGetGooglePlusProfileId() { | |
Logger.log('profileId:' + getGooglePlusProfileId('104512463398531242371')); | |
Logger.log('profileId:' + getGooglePlusProfileId('https://plus.google.com/u/0/+GoogleDevelopers/about')); | |
Logger.log('profileId:' + getGooglePlusProfileId('https://plus.google.com/u/1/+GoogleDevelopers/')); | |
Logger.log('profileId:' + getGooglePlusProfileId('https://plus.google.com/+GoogleDevelopers')); | |
Logger.log('profileId:' + getGooglePlusProfileId('https://plus.google.com/+GoogleDevelopers/about')); | |
Logger.log('profileId:' + getGooglePlusProfileId('https://plus.google.com/+GoogleDevelopers/')); | |
Logger.log('profileId:' + getGooglePlusProfileId('https://plus.google.com/u/0/104512463398531242371/about')); | |
Logger.log('profileId:' + getGooglePlusProfileId('https://plus.google.com/u/1/104512463398531242371/')); | |
Logger.log('profileId:' + getGooglePlusProfileId('https://plus.google.com/104512463398531242371')); | |
Logger.log('profileId:' + getGooglePlusProfileId('https://plus.google.com/104512463398531242371/about')); | |
Logger.log('profileId:' + getGooglePlusProfileId('https://plus.google.com/104512463398531242371/')); | |
} | |
function getGooglePlusProfileId(url) { | |
var profileId = null; | |
var qRe = new RegExp("^([0-9]+)$"); | |
var urlTest = qRe.exec(url); | |
if (urlTest != null) { | |
profileId = urlTest[1]; | |
} else { | |
qRe = new RegExp("^https://plus.google.com/(u/[0-9]/|)([0-9]+)(/[a-z]+|)(/|)$"); | |
urlTest = qRe.exec(url); | |
if (urlTest != null) { | |
Logger.log(urlTest); | |
profileId = urlTest[2]; | |
} else { | |
qRe = new RegExp("^https://plus.google.com/(u/[0-9]/|)(\\+[A-Za-z0-9]+)(/[a-z]+|)(/|)$"); | |
urlTest = qRe.exec(url); | |
Logger.log(urlTest); | |
profileId = urlTest[2]; | |
} | |
} | |
if (!profileId) { | |
throw 'failed to get profile Id'; | |
} | |
return profileId; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment