r/GoogleAppsScript • • Nov 11 '21

Question I need help exporting all my directory contacts from Google Contacts

I am only able to export my contacts list. However, I want to export the whole directory to csv. It says I cannot export multiple contacts from directory. I feel like I am missing something simple. Is there are script for this export? Or any tool I could use?

I have searched around the internet and found something that may be close. This was the script, but I could not get it to work, it was giving me some 'await' error. I don't know any Javascript so I cannot fix it. I was hoping someone might be able to assist me to get this working. Here is what I had found

https://webapps.stackexchange.com/questions/85768/how-to-download-all-directory-contacts

8 Upvotes

59 comments sorted by

1

u/Awemahhwe Nov 11 '21

Use Microsoft Edge. The script works.

1

u/gblawal Nov 12 '21

Am I supposed to run it in App Script? Where and how should I run it?

1

u/Awemahhwe Nov 12 '21

While on Google Directory page right click anywhere then choose inspect from the pop up list, a bunch of HTML code will show up then change from Elements to Console tab and paste the script and hit enter.

1

u/gblawal Nov 12 '21 edited Nov 12 '21

So I see it running now, but I don't see any contacts, just lines that say: Completed iteration; 2000/16101366 = 0.01242130636618036%

Where would I see the final results? Where is it saving to? When the script finishes, what will I have and in what format? Should I add the line that is in the comment which says JSON.stringify(Array.from(exportedContactsStorage))

I want to be able to see the output. Maybe at the end or during. So that I can save the output. Or is there a way to write the output to a file or something? Sorry for the dumb questions.

Thank you very much, by the way.

1

u/Awemahhwe Nov 12 '21

Wait for it to finish then paste: JSON.stringify(Array.from(exportedContactsStorage)) and it will save the file as json which you can then convert to csv or any format you want.

1

u/Dannymeashoyt Jun 13 '22 edited Jun 13 '22

it says blocked by client, something about json has fast = true, authuser1
tried it on edge, and nothing happens

2

u/AryanRanderiya Mar 30 '24

Hey I created a python script that automates this using the Google People API. Check it out here: https://github.com/aryanranderiya/GoogleContactsEmailScraper

1

u/climbTheStairs Sep 07 '25

this was a life saver for me, thank you so much!

1

u/1Mohnnd_ Mar 22 '24 • Take My Silver

For whoever face the same problem,

I find a solution, You can create a email, through the email menu press the word "To" You can see a new table showing up, select Directory from the menu in the right then click select all in the left side. Now doing this will put every single email in your recipients list in that email, it could lag your computer as there are so manu recipient but try your best to press Ctrl + A so you can select all of the recipients and copy them And paste the whole recipients to a txt file for example.

You can ask Chatgpt to create a python code to organize the recipient and make them as CSV format.

It could be a complicated answer, but yea it's better than nothing. At least there is a way.

1

u/retardedgummybear12 Jun 04 '24 edited Jun 04 '24

This is the only thing here actually works!!!!!!!!! Super simple and fast! Only downside is that it's name/email only (which is fine for me)

1

u/retardedgummybear12 Jun 04 '24

I just pasted into textedit (macos app) and had it replace ", " with a newline.

1

u/1Mohnnd_ Jun 20 '24

Glad it worked with you! this is the most random solution tho 😂

1

u/CGlow_News2918 Jul 11 '24

When I did it, I only got 30 contacts.

1

u/1Mohnnd_ Sep 18 '24

It could be something with your organization settings. I just got 23000 emails from the same method. It still works!

1

u/Cicada_ace Apr 08 '25

It doesn't work with more than 100,000 contacts...help!!

1

u/jscreatordev Aug 23 '26

ever found a fix?

1

u/BeAuryn Sep 09 '25

This actually works. Thank you! I cleaned up the data using Notepad++

1

u/RemcoE33 Nov 11 '21

This is a JavaScript function that cannot run in apps script. I can take a look tomorrow. UTC+1

1

u/CompetitiveHat9284 Jul 05 '22

You can export all directory contacts by installing this Chrome extension:

https://chrome.google.com/webstore/detail/mlkgbjmmgdmmlggeemddlpkfefmbnnnf

1

u/Ultraman88 Jul 13 '22

Was so happy to see your reply. however, Doesnt seems to load (stuck at Fetching data) for 430k contact list. Are you the creator?

1

u/CompetitiveHat9284 Jul 13 '22 edited Jul 13 '22

however, Doesnt seems to load (stuck at Fetching data) for 430k contact list. Are you the creator?

Try not to touch the browser until it finishes. Does it show progress percentages ("Fetching data X%")?

and yes, I created it.

1

u/Special-World761 Oct 03 '22

For me it doesn't seem to work, it just opens a duplicate tab and does nothing.

1

u/darumdarimduh Aug 31 '23

Hello. Thank you for this. However, the phone numbers do not reflect on the CSV file. Is it its limitation? if not, what can I do? Thanks

1

u/Medium_Recover_489 Dec 07 '23

dude please help me to extract just 30k contacts lol that guy done 430k contacts please help me just mails and name need

1

u/Keyboardsheep83 Aug 17 '22

The script doesn't work because Google Contacts changed a bit, but all you need to do is add another .parentElement to the script. I've suggested an edit in the StackExchange but until then, this is the functional script:

function sleep(ms) {
    return new Promise((resolve) => {
        setTimeout(resolve, 4000);
    });
}

window.exportedContactsStorage = new Set();
window.scroller = document.querySelectorAll('.ZvpjBb.C8Dkz')[0].parentElement.parentElement.parentElement.parentElement.parentElement;
while (scroller.scrollHeight - scroller.scrollTop > 400) {
    for (let element of document.querySelectorAll('.ZvpjBb.C8Dkz')[0].querySelectorAll('.XXcuqd')) {
        if (element.firstChild.childNodes.length === 1) {
            break;
        }
        let name = element.firstChild.childNodes[1].innerText;
        let job = element.firstChild.childNodes[2].innerText;
        let email = element.firstChild.childNodes[3].innerText;
        let phone = element.firstChild.childNodes[4].innerText;
        window.exportedContactsStorage.add(JSON.stringify({'name': name, 'job': job, 'email': email, 'phone': phone}));
    }
    scroller.scrollTo({
        top: scroller.scrollTop + 400,
        behavior: 'smooth'
    });
    console.log(
        'Completed iteration;',
        scroller.scrollTop.toString() + '/' + scroller.scrollHeight.toString() +
        ' = ' + (scroller.scrollTop / scroller.scrollHeight * 100).toString() + '%'
    );
    await sleep(4000);
}

1

u/AL42Gaming Feb 01 '23

This doesn't seem to be working. Any tips?

1

u/AryanRanderiya Mar 30 '24

1

u/Jam10000 May 22 '24

Where do I enter these commands?

1

u/AryanRanderiya May 23 '24

You just install python, download the script from the link I sent above, and run the commands in your terminal / cmd / powershell

1

u/Jam10000 Jun 15 '24

Sorry for my late response. Is downloading the script included in the command:

git clone https://github.com/aryanranderiya/GoogleContactsEmailScraper.git

If so, I am getting a syntax error for "clone". I did download python but I am confused as to what to download as it isn't clear.

A screenshot of the error is shown here: https://ibb.co/7ySNRgT

1

u/AryanRanderiya Jun 15 '24

Okay so install git, then open "powershell" then run the commands. right now you're running the command inside the python terminal which is wrong. You need to run the commands inside powershell or command prompt. You only need python to make the script work.

1

u/Jam10000 Jun 17 '24

I downloaded git from gitforwindows and ran the commands in powershell. Unfortunately I am getting an error with pip which is strange because I have Python installed?

https://ibb.co/HFt1Nmv

1

u/AryanRanderiya Jun 17 '24

Try searching and downloading pip

1

u/Jam10000 Jun 17 '24

I still get the same error and pip was in both my user folder and my downloads folder. I used the standalone zip from https://bootstrap.pypa.io/pip/pip.pyz

https://ibb.co/p0X80S3

1

u/Jam10000 Jun 17 '24

Disregard my last comment - I ended up getting to install pip! My next troubles are actually running the script. Any ideas? https://ibb.co/VMK8qbp

1

u/Jam10000 Jun 25 '24

Heyo, it's been a week. My access to the directory expires on June 30 and I've done what you asked so I hope we can continue troubleshooting!

→ More replies (0)

2

u/[deleted] Nov 11 '21 edited Nov 11 '21

[removed] — view removed comment

1

u/[deleted] May 17 '22

Google takeout doesn't include directory data because it's not 'yours' so to speak.

1

u/[deleted] May 17 '22

[removed] — view removed comment

1

u/[deleted] Jun 01 '22

Sadly, no. I ended up making a small python script to manually click on every single entry, add them to my contacts, then download the csv of that. A little roundabout but it worked out in the end haha

1

u/Dannymeashoyt Jun 13 '22

can you send it to me please?? help is appreciated

1

u/[deleted] Jun 13 '22

I'm sorry, but it wouldn't be very useful for you. I just used the mouse library to click the contacts, scroll, and continue clicking. Since the scroll values are specific to my browser, it would be much faster for you to just remake it yourself.

1

u/RareAd5542 Jul 13 '22

Any chance you could send the script to me? I have the mouse library as well and could easily modify your script accordingly. It will save me 12,638 clicks!

1

u/[deleted] Jul 14 '22

It saved me about 27,000 clicks, but it wasn't perfect. I missed a few people on the list. If that still fits your criteria, this is how I made it:

Go to the directory tab of google contacts, then make a for loop of range 20ish, clicking the checkbox of each contact, then moving the cursor down 10 pixels (or so, don't remember exact value). After its clicked 20 contacts, scroll down until the next unchecked contact is in the same position as the for loop starts out at, and continue. The goal is to let the program run for a while, then click "add to contacts". (You can't download a csv of the directory but you can download a csv of your contacts.) Something to note: you can only add 1000 people to your contacts at a time, so you have to incorporate that into your program as well. I took the lazy route and manually overviewed the program, and whenever it reached 900 or so I stopped it and added them to my contacts. It took about 15 minutes overall. Also, add a delay between clicks on the contacts, as that will cause you to lose some. If I still had the program, I'd send it, but sadly I don't. Good luck!

PS: If you make the program but theres something wrong with it, I'm happy to help. Just respond to this comment.

1

u/1Mohnnd_ Jan 17 '24

did you found any better solution? it's funny your post was 2 years old and I'm now facing the same scenario with 19000 contacts

1

u/Down200 Nov 01 '24

I've been using this little javascript snippet from this SO post whenever I need to scrape my directory: https://webapps.stackexchange.com/questions/85768/how-to-download-all-directory-contacts/145697#145697

Found this reddit post a year or so after I last 'exported' the list hoping for a better tool, guess I'll have to go back to the scuffed javascript scraper :(

→ More replies (0)

1

u/Medium_Recover_489 Dec 07 '23

hey please share me the script asap please dude i need urgent