Skip to content


Folders and files

Last commit message
Last commit date

Latest commit



13 Commits

Repository files navigation

ContactsSocialPhotos for Google Apps Script

ContactsSocialPhotos scans your contacts for social network URLs or IDs and sets the profile picture to the social network account profile picture.


Watch the HowTo Setup Video


After the first run you have to open the logs (Cmd|Ctrl + Enter) and open the OAuth url(s) manually, thusly (a) token(s) will be generated, which will be refreshed automatically in the future.

In Google Developer Console add the following URL as Authorized redirect URIs:{SCRIPT-ID}/usercallback
(You can find the Script ID in File > Project properties > Script ID.)
After adding the authorized redirect URI it can take a while. Just try the authorization again if you get a 401 error.


The options parameter is a JavaScript object:

	// Set 'contacts' (object) to:
	// { clientId: '...', clientSecret: '...' }
	// (Generate credentials for OAuth. In Apps Script:
	//  Resources > Developer Console Project... > 'project-id-...'
	//  > Credentials )
	contacts: {
	  clientId: '...',
	  clientSecret: '...'
	// Set 'xing' (object or boolean) to:
	// false to deactivate
	// true to activate without OAuth (only public profiles)
	// { consumerKey : '...', consumerSecret: '...' } to activate with OAuth
	// (Generate test key for OAuth:
	// )
	xing: {
	  consumerKey: '...',
	  consumerSecret: '...'
	// boolean, if the contacts url addresses should be checked for facebook
	// profile urls
	facebook: 1,
	// boolean, if the contacts email addresses should be checked for
	// gravatars (could slow down the first runs)
	gravatar: 1


  • Create a new Google Apps Script file and give it a project name.
  • In Resources > Libraries... search for the library:
    and click on Select.
  • Select the newest version and leave development mode turned off.
  • Click on Save and add the following code (you can remove the myFunction function):
// The main function to run the ContactsSocialPhotos
function contacts() {;

// Options (see "Options" in the
function opts() {
	return {
		contacts: {
			clientId: '...',
			clientSecret: '...'
		xing: {
			consumerKey: '...',
			consumerSecret: '...'
		facebook: 1,
		gravatar: 1

// This function will be called after any OAuth authorization.
function authCallback(request) {
	return ContactsSocialPhotos.authCallback(request, opts());
  • Modify the options (the object in the opts function). The contacts OAuth credentials are required (see "Options" above).
  • Run the contacts function.

First run

If it is your first run you get an error message. Open the logs (Cmd|Ctrl + Enter), copy the OAuth links, and open them in a new window. After both OAuth authorizations succeeded re-run the contacts function. This time the script should load a while (the Google Contacts API is slow).

Logs and Errors

After each run you can view the logs to see which contacts profile picture has been successfully changed. If you get a timeout error just re-run the script. The script caches some requests so that it can continue after each crash.

Add triggers (cron jobs)

Click on Resources > Current project's triggers to add the contacts function as a Time-driven trigger. You could execute it once or twice a day to stay updated.

HowTo Setup Video

ContactsSocialPhotos - Howto create OAuth credentials


ContactsSocialPhotos scans your Google Contacts for social network URLs or IDs and sets the profile picture to the social network account profile picture.







No releases published


No packages published