Get Linkedin profiles in Google Sheets with a Custom Formula

Giacomo Melzi
6 min readFeb 9, 2022

--

Some time ago, I made a custom Google Sheets formula to automatically get the Linkedin profile of a person/company. It can be helpful to anyone using Google Sheets as a CRM or recruitment, product feedback, or marketing tool. It saved me a lot of boring copy/pasting, so hopefully, it can save some time for you as well 😎

Linkedin google sheets formula

I’ll briefly explain how the formula works and share a quick (kinda 😅) implementation guide.

If you get stuck or you like it more, you can watch the video guide:

How it works

Since Linkedin profiles are behind a login (you have to be logged in to check someone’s profile), the formula relies on a workaround. The script performs a domain-constrained search via the Google Custom Search API.

That’s something anyone can do manually in a standard Google search. Just try adding site:{domain} before your search query, and your results will be filtered by domain.

Of all the results, the script will take the first profile (or company in case you added the second parameter as true) with the assumption it will be the best result (more on this in the Limitations section)

The formula has three parameters:

  • query: the name of person/company whose profile you wanna find
  • company: write true if the value of query is a company. If you don’t write anything, the value is going to be false by default.
  • index: the index of the result. If you want a different result from the first one, write the index number. If you put 0, it will return all the results (more on this in the Limitation section)

The formula comes with its own documentation, so you will see the tips like any other built-in formula.

Set up

Before importing the formula code, you will have to set up and create a custom search engine. It may sound intimidating, but it’s straightforward, and you don’t necessarily need to understand how it works behind the scenes; just follow along 😉

  1. Click on this link
  2. Click on the Get a Key button (in case you’re not logged in with your Google account, you will have to do it)
  3. Click on “Create new project” from the dropdown and name it whatever you want.
  4. Copy the generated API key and paste it somewhere (we will need it later)
  5. Now we need to create a custom search engine by clicking on this link and then clicking on the Add button.
  6. Name your search engine Linkedin (it can be anything tho). Select the Search specific sites or pages option and paste this in the field *.linkedin.com/* and click Add. Fill the reCAPTCHA if you’re asked to do so and click the Create button.
  7. Click on the custom search engine details page, copy the search engine ID number and paste it somewhere along with the API key we generated earlier.

It’s finally the time to put everything together.

Go on my GitHub page and copy the whole code as it is (it’s Javascript, in case you’re wondering) by clicking the copy icon.

Then open the Google sheet in which you want to use the formula; you will find Extensions → Apps Script on the top toolbar.

Paste the code you copied in the code editor.

Last step, at lines 34 and 35, there are two constants, apiKey, and searchEngineId. You have to replace “yourApiKey” and, you guessed it, “yourSearchEngineId” with the values you generated in the steps before. Make sure to wrap the values you’re going to paste in quotes (single or double, it’s the same). Like this:

const apiKey = "yourKey1233456789"

Once done, click Save and then Run. A popup will ask to authorize the use of several services, it looks scary but it’s not; it’s only asking you to allow calls to external services (Google Search) and right to modify the sheet.

The code doesn’t need any changes besides these so you can close the Apps script editor. You’re good to go now, give the formula a try! 🎉

Keanu approves
Keanu approves

That’s it 😄 The formula should already show up in the suggestions; if it doesn’t, just try reloading the page.

Note: The code is under MIT license meaning anyone can use it for free but if you do, make sure to give/keep the credit to the author, in this case, yours truly :)

Limitations

Quotas: Google Custom Search API queries are capped at 100 free calls/day. It may be a limitation the first time if you are bulk-adding profiles, but it won’t if you add profiles gradually. Although this formula was designed with ease of use in mind and not bulk processing, in case you need it, you can buy 1000 calls for 5$ from Google.

It’s important to highlight that the formula will run every time you open a sheet. Likewise, each time there will be a change in the content of the referenced cells. To prevent unwanted calls, you may want to copy the formula results and paste them as values.

Results: As I said in the how to use section, by default, the formula will get the first result of the Custom Search query. In some cases, especially with common names, the result you’re looking for might not be the first. You may be tempted to try to concatenate more info about the profile in the query. Still, although the API call will be correct, results are often inconsistent for a weird reason.

That’s a structural limitation of the formula, but it works just fine in most cases.

To provide some more flexibility, I’ve added a third formula parameter to enable the manual selection of the index of the results. Default is 1, so the first result of the query (well, technically index 0 since it is an array), if you want to pick the second result, you will put 2, the third 3, etc. If you put 0, it will return all the results (capping at 10), so you can have a peek and check which is the correct one.

One more thing 🙋‍♂️

If you like this kind of content follow me on Likendin, Medium or just subscribe to the newsletter, to get more content like this 😉

P.S. If you want to have a look at what else can be done, just check the end of video ;)

--

--