How to import social media statistics into Google Sheets: The Import Cookbook

Google Sheets has a powerful and versatile set of IMPORT formulas that can import social media statistics.

This article looks at importing social media statistics from popular social media channels into a Google sheet, for social network analysis or social media management. If you manage a lot of different channels then you could use these techniques to set up a master view (dashboard) to display all your metrics in one place.

The formulas below are generally set up to return the number of followers (or page likes) for a given channel, but you could adapt them to return other metrics (such as follows) with a little extra work.

Caveats: these formulas occasionally stop working when the underlying website changes, but I will try to keep this post updated with working versions for the major social media statistics.

Example workbooks: Each example has a link to an associated Google Sheet workbook, so feel free to make your own copy: File > Make a copy....


  1. Facebook
  2. Twitter
  3. Instagram
  4. Google+
  5. Youtube
  6. Pinterest
  7. Alexa rank
  8. Quora
  9. Reddit
  10. Spotify
  11. Soundcloud
  12. GTmetrix
  13. Linkedin
  14. Sites that don’t work and why not
  15. Closing thoughts
  16. Resources

How to import social media statistics into Google Sheets with formulas

facebook icon Import Facebook data

Start with the Facebook page URL in cell A1, e.g.

Here is the formula to extract page likes:

=VALUE(SUBSTITUTE(IMPORTXML(A1,"//span[@id='PagesLikesCountDOMID']")," likes",""))

Alternative formula:

Here is an alternative formula to extract the page metadata, which includes the likes:


the formula to extract likes is:

=VALUE(REGEXEXTRACT(REGEXEXTRACT(SUBSTITUTE( IMPORTXML(A1,"//meta[@name='description']/@content"),",",""),"\d{1,}.likes"),"\d{1,}"))

and to extract the “talking about” number:

=VALUE(REGEXEXTRACT(REGEXEXTRACT(SUBSTITUTE( IMPORTXML(A1,"//meta[@name='description']/@content"),",",""),"\d{1,}.talking"),"\d{1,}"))

The following screenshot shows these formulas:

facebook social media statistics

See the Facebook Import Sheet.

^ Back to Contents

twitter logo Import Twitter data

Start with the Twitter handle URL in cell A1, e.g.

Here is the formula to extract follower count:

=QUERY(IMPORTXML(A1,"//a[@data-nav='followers']"),"select Col2")

Pro-tip: If you find this formula gives an error, wrap it in an IFERROR function and call the IMPORTXML function a second time, but add a “/” to the end of the Twitter handle. This should then pull out the follower number for you (it requires that your Twitter handle in cell A1 does NOT have a “/” at the end):

=IFERROR(QUERY(IMPORTXML(A1,"//a[@data-nav='followers']"),"select Col2"),QUERY(IMPORTXML(A1&"/","//a[@data-nav='followers']"),"select Col2"))

The following screenshot shows these formulas:

twitter social media statistics

Note 1: These Twitter formulas seem to be particularly volatile, working fine one minute, then not at all the next. I have two Sheets open where it’ll work in one, but not the other!

Note 2: For Twitter handles with extremely large followings, in the millions, this will return a result with millions shown as “M” (e.g. 5,650,000 = 5.65M):

twitter_v2 import

We can use a quick SUBSTITUTE formula in C1 to convert to the equivalent million number:


Of course, this introduces a degree of inaccuracy as it records the number to the nearest ten thousand.

See the Twitter Import Sheet.

^ Back to Contents

Build Business Dashboards With Google Sheets and Data Studio

Digital marketing dashboard in Google Sheets
  • Learn how to build beautiful, interactive dashboards in my online course.
  • 9+ hours of video content, lifetime access and copies of all the finished dashboard templates.
  • Learn more

instagram logo Import Instagram data

Start with the Instagram page URL in cell A1:

Then, this formula in cell B1 to extract the follower count:

=VALUE(REGEXEXTRACT(REGEXEXTRACT(QUERY( IMPORTXML(A1,"//*"),"select Col3"),"followed_by.{15,}"),"[0-9]+"))

The following screenshot shows these formulas:

instagram data

Oo-er, this one’s a bit funky!

I wasn’t able to import the precise “followed_by” class so I’ve used some REGEX to extract the followers count tag from the data I’ve imported.

In a nutshell, the REGEXEXTRACT formula extracts this snippet: followed_by": {"count": 120}, "country_bl. The second REGEXEXTRACT formula then extracts the the digits and finally VALUE converts to a number.

If this causes an error, try wrapping with this alternative REGEXTRACT method (for large accounts):

=VALUE(IFERROR(REGEXEXTRACT(REGEXEXTRACT(QUERY( IMPORTXML(A1,"//*"),"select Col3"),"followed_by.{15,}"),"[0-9]+"),REGEXEXTRACT(REGEXEXTRACT(QUERY( IMPORTXML(A1,"//*"),"select Col3"),".{1,}.has_blocked_viewer"),"[0-9]+")))

See the Instagram Import Sheet.

^ Back to Contents

google-plus logo Import Google+ data

With the URL in cell A1:

this formula in cell B1, again using REGEX to extract the specific datapoint, will get the followers of the Google+ account:

=VALUE(SUBSTITUTE(REGEXEXTRACT(QUERY(IMPORTXML(A1,"//div[@class]"),"select Col2"),"[0-9].*[0-9].*[0-9]{1,}.followers")," followers",""))

The following screenshot shows this formula (actually shows a prior version of this formula):

Pro-tip: If you find this formula gives an error, wrap it in an IFERROR function and call the IMPORTXML function a second time, but add a “/” to the end of the Google+ handle. This should then pull out the follower number for you (it requires that your Google+ handle in cell A1 does NOT have a “/” at the end):

=IFERROR(VALUE(SUBSTITUTE(REGEXEXTRACT(QUERY(IMPORTXML(A1,"//div[@class]"),"select Col2"),"[0-9].*[0-9].*[0-9]{1,}.followers")," followers","")),
VALUE(SUBSTITUTE(REGEXEXTRACT(QUERY(IMPORTXML(A1&"/","//div[@class]"),"select Col2"),"[0-9].*[0-9].*[0-9]{1,}.followers")," followers","")))

See the Google+ Import Sheet.

Alternative formula to try for Google+, submitted by one of the students of my online Google Sheets and Data Studio dashboard course:

=VALUE(SUBSTITUTE(IMPORTXML(A1,"//div[@class='C98T8d GseqId b12n5']")," followers -",""))

^ Back to Contents

youtube logo Import YouTube data

Start with the YouTube channel URL in cell A1:

To get the number of subscribers to a YouTube channel, use this formula in cell B1:

=MID(QUERY(IMPORTXML(A1,"//div[@class='primary-header-actions']"),"select Col1"),31,20)

To get a channel’s total views, you need to use the about page as your URL in cell A1:

Then use this formula to extract channel views:


The following screenshot shows these formulas:

youtube data

See the YouTube Import Sheet.

^ Back to Contents

pinterest logo Import Pinterest data

In cell A1, enter the following URL, again replacing benlcollins with the profile you’re interested in:

Then in the adjacent cell, B1, enter the following formula:

=VALUE(QUERY(IMPORTXML(A1,"//span"),"select Col1 limit 1",0))

to get the following output:

pinterest data

Note, you can also get hold of the profile metadata with the import formulas, as follows:


See the Pinterest Import Sheet.

^ Back to Contents

alexa logo Import Alexa ranking data

Here there are two metrics I’m interested in – a site’s Global rank and a site’s US rank.

Global Rank

To get the Global rank for your site, enter your URL into cell A1 (replace

and use the following helper formula in cell B1:

=QUERY(ArrayFormula(QUERY(IMPORTDATA(A1),"select Col1") & QUERY(IMPORTDATA(A1),"select Col2")),"select * limit 1 offset " & MATCH(FALSE,ArrayFormula(ISNA(REGEXEXTRACT(QUERY(IMPORTDATA(A1),"select Col1") & QUERY(IMPORTDATA(A1),"select Col2"),"Global rank icon.{10,}"))),0)+1)

and then extract the rank in cell C1:


US Rank

Assuming you have the Alexa URL in cell A1 again, then the US rank is extracted with this helper formula:

=QUERY(ArrayFormula(QUERY(IMPORTDATA(A1),"select Col1") & QUERY(IMPORTDATA(A1),"select Col2")),"select * limit 1 offset " & MATCH(FALSE,ArrayFormula(ISNA(REGEXEXTRACT(QUERY(IMPORTDATA(A1),"select Col1") & QUERY(IMPORTDATA(A1),"select Col2"),"title='United States Flag'.alt.{50,}"))),0))

and this formula to extract the actual rank value:


The following screenshot shows these formulas:

alexa data

See the Alexa Ranking Import Sheet.

^ Back to Contents

Build Business Dashboards With Google Sheets and Data Studio

Digital marketing dashboard in Google Sheets
  • Learn how to build beautiful, interactive dashboards in my online course.
  • 9+ hours of video content, lifetime access and copies of all the finished dashboard templates.
  • Learn more

quora logo Import Quora data

In this instance, I’ve imported the number followers Barack Obama has on Quora.

Quora is a little bit different because I need to use the URL and the profile name in my formula, so I’ve kept them in separate cells for that purpose. So in cell A1, add the generic Quora URL:

And then in cell B1, add the profile name:


Then the formula in C1 to get the number of followers is:

=VALUE(QUERY(IMPORTXML(A1&B1,"//a[@href='/profile/"&B1&"/followers']"),"select Col2"))

The following screenshot shows this formula:

quora data

See the Quora Import Sheet.

^ Back to Contents

reddit logo Import Reddit data

Here, I’m using the funny subreddit as my example.

In A1:

To get the number of followers of this subreddit, use this formula in cell B1:


Bonus: To get the number of active viewers of this subreddit:


The following screenshot shows these formulas:

reddit data

See the Reddit Import Sheet.

^ Back to Contents

spotify logo Import Spotify Artist followers

Here’s a method for extracting the number of followers an artist has on the music streaming site Spotify.

First, find your favorite artist on Spotify and right-click their name. From the menu that pops up, choose “Copy Spotify URI”. Paste that into your Google Sheet in column B, and delete the “spotify:artist:” string to leave just the ID, as shown in the image further down this post.

So you should have an artist name in cell A1:


and the artist’s unique URI in cell B1:


Add this URL (the API endpoint) into cell C1:

and then combine the artist URI and API endpoint (columns C & B) with this formula, to put the full URL into column D:


Then put the following formula into column E to extract the followers:

=VALUE(MID(QUERY(IMPORTDATA(D1),"select Col1 limit 1 offset 7"),9,25))

The following screenshot shows these formulas (click to view larger version):

spotify data

Note, for the technical amongst you, copy the full API url (column D) and paste it into a new tab of your web browser. There you’ll see the raw JSON data before we import into Google Sheets, and you can clearly see the followers count:

spotify JSON data

Read more about the Spotify API and find other end points here:

And the detailed information on the get artist information end point we’ve used in this example:

See the Spotify Import Sheet.

^ Back to Contents

soundcloud logo Import Soundcloud data

Start with the Soundcloud page URL in cell A1, e.g.

Here is the formula to extract page likes:

=ArrayFormula(VALUE(REGEXEXTRACT(QUERY(SORT(IFERROR(REGEXEXTRACT( IMPORTXML(A1,"//script"),"followers_count..\d{1,}"),""),1,FALSE),"select * limit 1"),"\d{1,}")))

Alternative formula:

Here is an alternative formula to extract the page metadata, which includes the likes:


the formula to extract likes is:

=VALUE(REGEXEXTRACT(REGEXEXTRACT(SUBSTITUTE( IMPORTXML(A1,"//meta[@name='description']/@content"),",",""),"\d{1,}.Followers"),"\d{1,}"))

and to extract the “talking about” number:

=VALUE(REGEXEXTRACT(REGEXEXTRACT(SUBSTITUTE( IMPORTXML(A1,"//meta[@name='description']/@content"),",",""),"\d{1,}.Tracks"),"\d{1,}"))

The following screenshot shows these formulas:

soundcloud data

See the Soundcloud Import Sheet.

^ Back to Contents

gtmetrix_logo Import GTmetrix data

GTmetrix is a website that analyzes website performance.

You need to grab the correct URL before you can start scraping the data. So navigate to the GTmetrix site and enter the URL and hit analyze. You’ll end up with a URL like this:

Those last 8 characters (“BcHv78bP”) appear to be unique each time you run an analysis, so you’ll have to do this step manually.

Then in column B, I use this formula to extract the Page Speed Score and YSlow Score, into cells B1 and B2:


and this formula in cell B3, to get the page details (Fully Loaded Time, Total Page Size and Requests) in cells B3, B4 and B5:


The following screenshot shows these formulas:

gtmetrix data

See the GTmetrix Import Sheet.

^ Back to Contents

linkedin logo Import Linkedin data

This formula is no longer working for extracting Linkedin followers and I have not found an alternative.

In cell A1:

This formula used to work to get the number of Linkedin followers, but no longer:

=QUERY(IMPORTXML(A1,"//div[@class='member-connections']"),"select Col1")

and the output:

linkedin import

There is no example sheet for Linkedin since the formula is no longer working.

^ Back to Contents

cancel icon Sites that don’t work and why not

I’ve tried the following sites but the IMPORT formulas are unable to extract the social media statistics:

  • Linkedin (see above)
  • Similar Web
  • Twitch
  • Mobcrush
  • Crunchbase
  • Majestic SEO

These are all modern sites built using front-end, client-side Javascript frameworks, so the IMPORT formulas can’t extract any data because the page is built dynamically in browser as it’s loaded up. The IMPORT formulas work fine on sites built in the traditional fashion, with lots of well formed HTML tags, where the social media statistics are embedded into the site markup that is passed from the server.

Compare this screenshot of the source code for Mobcrush, built using Angular JS it looks like (click to enlarge):

Angular front end

versus what the source code looks for this page on my website (click to enlarge):

benlcollins code

You can see the code for my site has lots of tags which the IMPORT formulas can parse, whereas the other site’s code does not.

If anyone knows of any clever way to get around this, do share!

Otherwise, you’re next option is to venture down the API route. Yes, this involves coding, but it’s not as hard as you think.

I’ll be posting some API focussed articles soon. In the meantime, check out my post on how to get started with APIs, or for a peak at what’s coming, take a look at my Apps Script + API repo on GitHub.

Loading error

Also, even when these formulas are working, they can be temperamental. If you work with them a lot, sooner or later you’ll find yourself hitting this loading issue all the time, where the formulas stop displaying any results:

Loading error

^ Back to Contents

settings logo Closing thoughts

These formulas are unstable and will sometimes display an error message.

I’ve found that adding or removing the final “/” from the URL can sometimes get the formula working again (the issue is to do with caching).

I can make no guarantee that these will work for you or into the future. Whilst researching this article, I came across several older articles where many of the formulas no longer work. So things change!

To summarize: Caveat Emptor!

^ Back to Contents

link icon Resources

^ Back to Contents

As always, leave any comments, corrections or request other social media statistics below.

Icons from Freepik.

138 thoughts on “How to import social media statistics into Google Sheets: The Import Cookbook”

  1. This is awesome! Thanks for putting it together.

    One metric I’m interested in adding is YouTube Subscribers, any chance you would know how to do this already?

    1. Thanks Michael, glad it was helpful!

      Try this formula to get YouTube subscribers:

      =mid(query(IMPORTXML(A1,"//div[@class='primary-header-actions']"),"select Col1"),31,20)

      where your YouTube account url is in cell A1.

        1. Nice work! Interesting to see that it takes a minute or so to load all of the data, with that many formulas.

          Also, I like your G+ formula, it’s much neater and more succinct than mine, so I’ll update the article. Cheers!

    1. Me too, can’t see anything that has changed in the source code though. Sometimes it grabs the followers counts, sometimes not. It’s a temperamental system as advertised πŸ™‚

    2. Hey Dave,

      I’m getting an #N/a error with my Linkedin import formulas too. The actual error message is telling me “Could not fetch url”, so the import function isn’t able to access the Linkedin url, so Linkedin must have changed something on their side I think. Am looking for a solution too! I’ll update the article if I can find an alternative solution.


  2. Hi Ben

    I found a code that works, not sure why


  3. Trying to post some code here, but it seems to disappear in the replay. Let’s try again…

    Copied the actual number (XPath) from Inspect view on followers page:

    Source from followers page:


  4. Hi and thanks for sharing this Ben!

    I set up my Google Spreadsheet as described in your article. It worked like a charm when I tested it for about 10-20 profiles at a time.

    But once I expanded the formulas to several hundreds/thousands of profiles the fields just remained blank. Even the fields that were displaying follower counts just fine before went empty after refreshing.

    Is there a limitation on queries? Does anybody elseexperience this problem?

    Thanks! Mike

    1. Hi Mike,

      I understand there used to be a limit of 50 in the old Google Sheets (see here:, but it was removed in the new Google Sheets, although there still seems to be some confusion (see:!topic/docs/AYGh1hZXKgI).

      Do the formulas give you any error messages? You could try running them in several separate Sheets and then aggregating into one master sheet using IMPORTRANGE() formulas.


      1. Thanks for the reply Ben! I will have a look into using several separate sheets and then aggregating into one master sheet using IMPORTRANGE() formulas.

        Regarding error messages:
        – Facebook works like a charm, even with a thousand accounts (unsing the script)
        – Twitter returns a zero even though the account clearly has more followers
        – Instagram and YouTube remain blank, no error message though

        Hope that helps with further analysis! πŸ™‚

        Best, Mike

  5. Thanks again. It works perfectly. Would you happen to know why the Twitter one gives perpetual error (sometimes it shows and others it disappears).

    Would you have an alternate string.


    1. Hi ssen,

      Sometimes adding or removing the final β€œ/” from the URL will make the formula work again. Caching can occasionally prevent the formulas functioning properly, so adding/removing the “/” effectively creates a new url, which forces the formula to fetch the data again. Also, these formulas are somewhat volatile overall, so will break if the structure of the webpage changes or the function cannot parse the webpage.

      I’ll post any alternatives here if I find them, so keep an eye out.

      A more robust way to get hold of social media data would be to use Google Apps Script to build a basic app that is connected to each service’s api, but this is obviously a great deal more work. It’s something I’ll write a post on in the future.

      Cheers, Ben

  6. Hi! Ben,
    I’m super happy with this post that you made. Two days ago I noticed that Instagram code (probably with their update) its making GSheets crash so bad.
    Will you help me to figure it out?


    1. Hi Ben,

      Big fan of the codes as it has helped me tremendously. I’m experiencing a similar issue that Luisa is experiencing. The formula does not seem to work for Instagram, and displays the follower count as “#N/A”. Also, I’ve noticed a large amount of code text located to the left-hand side of the page whenever I click on the follower count. Would you be able to assist?


    2. Hi Luisa!

      Yes, I had the same problem when I revisited my sheet. The code on Instagram’s website has probably changed. Thanks for letting me know! I’ll work on it and see if I can find an alternative πŸ˜‰


      1. And Michael, ditto for your comment. Thanks for stopping by and letting me know. I had the same weird chunk of text on the left side of my Google Sheet. I’ve removed the Instagram formula for now, pending an update!


  7. Hi Ben

    Thank youΒ β€”Β and all your commenters β€”Β for doing the hard work on this and sharing. This is an absolutely fantastic resource!

    As with other commenters, i’ve noticed the Regex for the Instagram formula returns quite a strange error.

    Finally, i’m wondering how often this data is automatically updated from the source? In searching around Google for how to get social media data into Sheets, I found this website which has similar formulas, and offers a script to re-fetch the data:

    Would that be necessary? Or is simply reloading the Sheet each time its reopened enough to fetch any updated data?

    Thanks once again, this really is a fantastic post!

    1. Hey Jamie,

      Thanks for stopping by and leaving a comment. Yes, the instagram and linkedin ones have stopped working right now. It’s a temperamental function!

      I think that whenever you open or refresh your worksheet the import formulas will go fetch the latest data, although I understand that caching can sometimes mean the most recent data is not fetched. If you have your Google Sheet open and the data changes on the underlying website (e.g. you gain a follower), then this will NOT automatically update in your sheet. You’d need to write a small script, per that (excellent) Geckoboard article.


  8. Hi Ben,

    Fellow developer here :). Thank you so much for your contribution, it really helps.

    Question tho, when I use your formula for Instagram, the spreadsheet gave me an error of “#VALUE!” – “Error
    Unable to parse query string for Function QUERY parameter 2: NO_COLUMNCol3”. Also, when I look at your demo, the value of Instagram on B8 is written “#N/A”. Is that normal?


    1. Hey Sophie, thanks for stopping by and leaving a comment. Unfortunately the instagram formula as described had stopped working. I’m working on a fix tho! πŸ™‚


      1. Hi Ben,
        I’m experiencing the same problem as Sophie; in some rows it gives results, but in most of them it returns to

        β€œ#VALUE!” – β€œError
        Unable to parse query string for Function QUERY parameter 2: NO_COLUMNCol3”

        I am using it for number of likes and comments of the posts in Instagram.

        Any help?

        1. Hi! Are you using the latest formula: =REGEXEXTRACT(query(IMPORTXML(A1,"//*"),"select Col3"),"followed_by.{12,}")? It’s been updated from the one which was causing issues for Sophie.

          It’s working well for me. Note that these IMPORTXML formulas are somewhat limited, so won’t work well if you’re trying to extract data for thousands of profiles at once.

          Other things you could try:
          – Replace “Col3” with “C”, this sometimes works instead.
          – Try adding a trailing backslash “/” (or removing it if you have one) to the instagram url. This forces the formula to re-run and overcomes the issue of these formulas sometimes not working because the data has been cached.

          Hope that helps!

            1. Sure thing, so “Col3” refers to the third column of the data that is imported by the IMPORTXML formula. This is the column that contains the follower information. The “{12,}” is regular expression in the REGEXEXTRACT formula, which extracts the snippet of data relating to the follower count.

              You can use this formula in the adjacent cell to then extract the count from the string:


              So like this:

              Instagram extract


  9. Hi Ben,

    Thanks a lot for the article! Unhappily, it does not seem to be working for retrieving data from Twitter. I get the following error: Impossible to analyse the parameter 2 of Query, QUERY : NO_COLUMN: Col2.

    1. Hi Vladimir,

      Yes, I’ve had this happen before too. Sometimes deleting and re-copying the formula fixes the situation. Otherwise, try changing “Col1” to “A”, “Col2” to “B” etc. and see if that helps (so your query would be “select B” rather than “select Col2”).


  10. Hi Ben,

    could it be that the instagram formula is not working anymore? It would be cool to update this one.


    1. Hi Daniel,

      Hmm, seems to still be working for me. πŸ€”

      Are you using the updated formula I posted?

      In cell A1:

      In cell B1:
      =REGEXEXTRACT(query(IMPORTXML(A1,”//*”),”select Col3″),”followed_by.{30}”)

      In cell C1:

      On my sheet, this one appears to still be working fine. The previous formula I posted had stopped working.

      Otherwise, sometimes re-pasting the formula resolves the issue, or adding/removing the final “/” on the url, e.g. try “” without the “/” at the end.

      Let me know if it works for you.


          1. Hey Ben,

            First of all thanks of these! Quite useful stuff!

            I’ve been having a problem with the IG formula

            =VALUE(IFERROR(REGEXEXTRACT(REGEXEXTRACT(QUERY( IMPORTXML(A1,”//*”),”select Col3″),”followed_by.{15,}”),”[0-9]+”),REGEXEXTRACT(REGEXEXTRACT(QUERY( IMPORTXML(A1,”//*”),”select Col3″),”.{1,}.has_blocked_viewer”),”[0-9]+”)))

            Its giving me back the number of people the account follows instead of the followers it has. Do you know why?? What do I need to change in the formula?! Thanks in advance

            1. Hmm, not sure. But try this formula:

              =REGEXEXTRACT(REGEXEXTRACT(query(IMPORTXML(A9,"//*"),"select Col3"),"followed_by.{12,}"),"[0-9]+")

              which is just a shortened version of that long formula. I’ve checked mine now and it’s giving me the followers count.


  11. I have a problem…

    the Facebook script

    it works good but,
    everyday it get error to me from (08:00 PM) to (01:20 AM)
    then run good from (01:20 AM) to all day until stoped again !!!
    sometime get error from (04:00 PM) or (06:00 PM)…. et.
    and get work again in (01:20 AM) !!!

    if you have solution to this problem, or can help me with any information.. !

    and thank you alot dear

    1. Hi Mohamed,

      Hmm, very strange. I’ve occasionally had a script stop working for a short period of time, but usually start working again within a few hours. I’ve not had a time issue like this one though.

      If it’s still happening, I’d suggest posting a question on the Google forums to see if anyone there can help you out:!topicsearchin/docs/category$3Aspreadsheets or try posting to Stack Overflow:


  12. Hi Ben,

    the twitter formula is working at the beginning, but then suddenly you get a #value error that i can’t get rid of anymore. Do you know how to solve this?

    Thank you so much!

    1. Hey Daniel,

      Yes, sometimes these import formulas stop working πŸ˜•

      I think one of the issues is with caching, so try re-pasting the formula or adding/removing the final β€œ/” on the url, e.g. if you’re trying β€œ” with the β€œ/” at the end, then remove the last “/” and try “”, or vice versa.

      Of the two twitter formulas in the worksheet, the second one seems to be more reliable!


        1. Nice work Daniel!

          For anyone else reading this, you’ll need to make a copy of the sheet (File > Make a copy…) to see the formula working. In the view-only mode it was showing a #N/A, but then worked perfectly when I made my own copy.

          Going to go away and spend sometime decoding this now πŸ˜‰

  13. Phenomenal work! There is a lot to play with here. I am particularly impressed that you cracked Instagram – I had messed with that in years past with no dice.

    On Twitter, a better route I found to deal with the 10K or 10M abbreviations, is to pull from the mobile URL. It gives precise numbers. You can see this in action in my (ever-evolving) TweetMasterDash:

    Heart @yorudan

    1. Thanks @yorudan! Great work with your TweetMasterDash spreadsheet, impressive stuff. Clever idea to pull from the mobile URL to get around that 10K or 10M abbreviations. Thanks for sharing!

      Cheers, Ben

  14. Hi Ben,

    this morning I realized that the fb_likes function is not working anymore. Are you experiencing the same problem? It says “TypeError: Cannot call method “getText” of null. (line 8).”


      1. Hi Ziya,

        See my comment to Daniel above. That version of the api is no longer supported! Will post a fix if/when I find one!


    1. Hi Daniel,

      Thanks for letting me know. Facebook recently deprecated v2.0 of their API, which caused this fb_likes function to stop working. Digging a little further into the fb_likes api call, I found the following error message confirming it:

      REST API is deprecated for versions v2.1 and higher (12)

      Also confirmed on the following FB page:

      Facebook API v2.0 deprecated


      Working on a solution, though I fear it will be more complex and involve authenticated calls to the API. Great project for the future though!


        1. Hey Jake,

          Both of these formulas appear to be working at the moment to import Facebook page likes:



          =substitute(importxml(A1,"//span[@id='PagesLikesCountDOMID']")," likes","")

          Thanks. I need to update the post!


          1. do you have any formula that would allow to get the number of member and the title of a facebook group .. i spent a whole night from your page formula but i reached by limit πŸ™

            for the members its in that code :
            1 710 membres

            for the title and example :
            HERE IS GROUP NAME

  15. Hi Ben,

    thanks for the good work – really helped me a lot setting up a google Dashboard for social media monitoring!

    For the facebook problem I could find a workaround extracting the likedata out of the meta-data of the fb page. It’s clunky (I think it gets tangled up in the fb security check), but it works in the long run. Using the following formula:

    =IMPORTXML(, “//meta[@name=’description’]/@content”)

    returns the string:

    “BuzzFeed. 8.189.336 likes Β· 1.507.877 talking about this. Worth sharing.”

    REGEXEXTRACT gets the value of likes/followers out of the string, here for values up to hundreds of millions:


    (which for sure can be optimized).


    1. Hi Jo,

      This is AWESOME! Thank you for sharing your solution with the rest of us, worked perfectly for me. Here’s an alternative to your regex formula:


      and the whole thing can be combined into a single formula:


      I’m sure it can still be optimized!

      Cool to see you use the VALUE function as well. I’d forgotten about that, so have been using this trick to convert to numbers =A1*1.

      Here’s a sheet with all of these setup.


    1. Thanks for the heads-up. Minor tweak to the REGEX formula and it’s working again. The new formula is:

      =REGEXEXTRACT(query(IMPORTXML(A1,"//*"),"select Col3"),"followed_by.{12,}")

      and then, to extract the exact follower count:



    1. Hey Steven, I’ve updated the instagram formula now and it works on any size account for me. Hopefully that fixes it for you too.


    1. Yes, you can. Great solution. I guess I had QUERY on the brain when I was writing all these different formulas, so missed the better solution to use INDEX. Will update the post to reflect. Thanks!

  16. Ben,
    Your formula to grab the subscribers count on YouTube works great! Is there anything similar that will show a channel’s total views?

      1. Brilliant! I’ve never paid much attention to the “about” page and didn’t realize that info was there. It works like a charm. Thanks for your help!

  17. Hello, trying tiny coping facebook method and always getting a “TypeError: Unable to call the method “getText” of the object null. (line 6).” message. Please, link me for updating info, best and thank in advance.

    1. Hi! The custom Facebook formula no longer works because they’ve changed the API. However, the other formulas listed in the article using the IMPORTXML method are still working.

  18. Ben, One last question (where I think I know the answer). Is there a way to grab a range of channel views on YouTube, specifically “Last week,” without getting into API’s? I suspect that that info on the Analytics page isn’t XML. I’ve set my Analytics default to “Last week,” but haven’t had any luck grabbing it. I’ve tried isolating what I think is the target from the html source code, but either that doesn’t work or I’ve isolated the wrong target.

    1. Yes unfortunately I think this is the realm of APIs. I’ve tried a few variations of IMPORTXML but can’t get past a message like this: “One account. All of Google.Sign in to continue to YouTube…..”. I’m sure it’ll be possible with Apps Script and APIs.

  19. Hi! This is a big help. However, I can’t seem to get Pinterest’s to work any longer- even the update you posted in the end of August.

    Any help would be appreciated! Thanks!

    1. Hey Daria,

      The updated formula:

      =substitute(query(IMPORTXML(A1,"//a"),"select * limit 1 offset 5"),"Followers","")*1

      is still working for me. The Google Sheet was out of date though, which I’ve updated just now.

      Try adding or removing a final “/” to the address – sometimes these IMPORT formulas get “stuck” with cached data, so you need to make Google think it’s a new URL and get the formula to re-import.

      Hope that helps.

      Cheers, Ben

  20. I am also having a problem getting the Pinterest followers. Using the code you provided I get this error.

    Function MULTIPLY parameter 1 expects number values. But ‘8.5kPins’ is a text and cannot be coerced to a number.

    I can of course take out the *1 at the end and it shows the text value. But I am wanting to of course perform analysis on the numbers

    1. Hey James,

      So what’s happening here is that the number of Pinterest follower is large enough that they abbreviate the number to show ‘8.5k’ with the ‘k’ representing 1000. So this will require some modification to the formula. Try this, where your Pinterest address is in cell A1:

      =value(substitute(substitute(query(IMPORTXML(A1,"//a"),"select * limit 1 offset 3"),"kPins","00"),".",""))

      Note – this pulls out the number of pins, it’ll be different if you want the number of followers:

      =value(substitute(substitute(query(IMPORTXML(A1,"//a"),"select * limit 1 offset 5"),"kFollowers","00"),".",""))

      Also, another note, these two formulas work for the thousands short-hand (“k”). If the Pinterest account has millions of followers, and the account shows e.g. “4.5MFollowers”, then you’ll need to change the “kFollowers” to “MFollowers” and the “00” to “00000” in the above code to make it all work.

      Hope that helps!


  21. Hello Ben

    Thank you very much for sharing these techniques.
    Might there be a way to extract the likes for one certain Facebook post, not the likes for the account?

    Thank you in advance,


    1. Hi Roselle,

      Haven’t tried this but I think this will require using script to access the API, which is a lot more complext than the IMPORT formulas. If I get time I’ll look into it tho and update you.


    1. I have some issues with the instagram import. It seems that the search for “followed_by” is not unique for every account, because sometimes the formula finds “followed_by_viewer” and that’s the wrong place to search for the “count” element. Does anyone have a solution for that?


      1. Hey Daniel,

        So that example has 0 followers right? So the HTML is different and the original formula can’t parse this example. A slight modification to the formula picks out the zero count:

        =REGEXEXTRACT(query(IMPORTXML(A1,"//*"),"select Col3"),"follows.{12,}")

        The original formula is working fine otherwise for me. If you have any other accounts you know where the formula isn’t working then let me know. The fix above may work in those cases too.


        1. Dave – can you share the Instagram example that’s not working? Formula still working fine for me, so I need to see what the error is.

          In the meantime try this slight modification, which might do the trick:

          =REGEXEXTRACT(query(IMPORTXML(A1,"//*"),"select Col3"),"follows.{12,}")

          Let me know if that works…

          Thanks, Ben

          1. Hey Ben,

            No joy, I got this error message on column c, row 1 – “In FIND evaluation, cannot find ‘}’ within ‘follows”: {“count”: ‘.”

  22. Ben,

    Looks like Alexa formula needs a tweak. There are now two strong tags with class = “metrics-data align-vmiddle”. And the first one also has an html comment in it (not sure if that is what breaks it).

    IMPORTXML returns “Imported Xml content can not be parsed”.

    I’m trying to get just the US rank, but I still struggle with understanding xpath queries.


      1. I’d love to see a solution to this as well. It looks like they’re pointing to their API for a solution now; was that there before?

        Thanks for opening my eyes to all sorts of new possibilities with Sheets, Ben! Between this and your page scraping article, I’ve got a lot of fun new things to try!

    1. Hey Dave,

      Tried and tried, but haven’t been able to find a solution using the IMPORTXML method. So instead I found an alternative using IMPORTDATA and lots of matching array formulas – it’s a monster, so hopefully in time a better solution will surface, but for now it works.

      Here’s the US rank formulas, with URL in A1, then in B1:

      =trim(query(sort(ArrayFormula(regexextract(query(importdata(A1),”select Col1″)&query(importdata(A1),”select Col2″),”United States Flag.+span.{10,}”)),1,TRUE),”select * limit 1″))

      Then in C1, extract the number:


      The Global rank formula is even worse! Here’s a link to a sheet with the solution:


    1. Hi Jamie,

      Unfortunately, I don’t think it’s possible because you need to be logged in to see the number of clicks on any shortlinks you’ve created. So the IMPORT formula can’t get past the login to see the data.


  23. Hey Ben,

    The Instagram update was working fine for awhile but now it’s not returning the followers count, just the following.

    “ProfilePage””: [{“”user””: {“”username””: “”uidesignpatterns””, “”country_block””:
    null, “”connected_fb_page””: null, “”follows””: {“”count””: 5820},
    “”requested_by_viewer””: false, “”followed_by””: {“”count”””

    1. Hey Dave,

      So you’ll need to change the formulas that parse this “ProfilePage” block. Try putting these two formulas in the adjacent cells:

      In A1:

      In B1: =mid(query(IMPORTXML(A1,"//*"),"select Col3"),find("ProfilePage",query(IMPORTXML(A1,"//*"),"select Col3")),190)

      In C1: =trim(regexreplace(regexreplace(B1,"[[:punct:]]",""),"[[:alpha:]]",""))

      In D1: =value(TRIM(RIGHT(SUBSTITUTE(C1," ",REPT(" ",LEN(C1))),LEN(C1))))

      Here’s a link to a working example in a spreadsheet:

      Hope that helps!


  24. Hi, Ben,

    Is it possible to grab likes count from a specific Instagram publication?

    For example I tried to parse viewer_has_liked from your photo: β€” with formula: =REGEXEXTRACT(query(IMPORTXML(A1;”//*”);”select Col3″);”viewer_has_liked.{25}”)

    But the result was only: viewer_has_liked”: false, “nodes”: [{“use
    There is no: count”: 26.

    Thanks for your articles, Ben!

  25. Hi Ben,

    Thank you so much for this formula! I’m working on a French version of google and translated it and it mostly works a treat!

    I have a few questions for you:

    1. Are you aware of a way to remove the commas from the numbers displayed? In French they are considered as points and my totals are messed up slightly.

    2. Some of my instagram profile accounts don’t work with the formula for example only brings me back 600 or so whereas the profile has 55.6K followers any ideas as to why?

    3. Anyway to copy the values of this say each month or week into a different cell so as to see the progress of one’s social reach as well as not having to enter numbers? I try copying only the value of the cell and it doesn’t want to work :/

    Again thank you! This really has saved me a lot of time πŸ™‚


    1. I just answered my q1 with an extra cell using replace/substiute formula it’s this in the French version of sheets: =SUBSTITUE(A1;”,”;””;)
      and this in the English version; =SUBSTITUTE(B6,”,”,””,)

    2. Hey Elena,

      Catching up on the blog comments now! Great that you’ve solved question 1, nice work πŸ™‚

      For Q2: Hmm, I’m getting errors with the Instagram formulas now, so looks like I’ll need to rework them. I’ll try to get round to some kind of update article in early 2017…

      For Q3: Have a look at this post about saving social media data using a little snippet of Apps Script. I think that should do the trick for you.

      Hope that helps!


  26. Hi Ben,

    Why are you using the xyz function even if we get the number of followers by using pqr function?

    xyz = query(IMPORTXML(A1,”//a[@data-nav=’followers’]”),”select Col2″)

    pqr = IMPORTXML(A1,”//a[@data-nav=’followers’]”)

    1. Hi Sowmay,

      The QUERY() wrapper function is used to pull out the follower number only, because the output of the IMPORT formula spreads across two columns, something like:

      Followers | 1,919

      So the QUERY just returns 1,919 and removes the word “followers”.


  27. Hi Ben,

    This is amazing work πŸ™‚

    Is there a way to pull the latest tweet date? I’d like to pull that to show when the last time an account tweeted.

    Many thanks

  28. Hi Ben,

    Is there a way you could include streaming sites? Twitch and Mobcrush? We really want to collect an accurate follower count.

      1. Hey Sarah,

        So I tried both of these sites but unfortunately I couldn’t extract data with the IMPORT formulas. πŸ™

        They’re built with client side Javascript, so don’t really have the metrics data in a structured XML or HTML format for the formulas to extract. You’ll have to see if they have APIs you can use.


  29. Great article! Helped me a lot.

    I have a comment and a doubt:

    – I tried using the IG formula and it worked just in some cases. Doing some sniffing around, I tried this generic formula instead and it worked properly. I hope it helps: =REGEXEXTRACT(mid(query(IMPORTXML(B2,”//*”),”select Col3″),find(“followed_by”&CHAR(34),query(IMPORTXML(B2,”//*”),”select Col3″)),35), “[0-9]+”)

    – Now the doubt: The values that I get using these formulas are updated automatically or is there a way to update them manually?


    1. Hey Henrique, I believe they get updated every time you open the sheet (or click into the formula and hit enter). However, I know they sometimes get hung up with cached data, so fail to update. What you can do is add a “/” to the end of the URL to force it to update.


  30. Hello Ben,

    Thank you so much for the update everything is working great! Would you have a suggestion on how to extract the estimated unique views of a website via, say, similar web?

    Thank you for all your help!


    1. Hey Elena,

      I tried Similar Web but it’s not possible to retrieve data via these IMPORT formulas because of the underlying structure of the website (more details why here). You’d have to look into the API to see if it’s possible.


  31. Hi Ben,

    Is there any tricks to get the live cricket score from websites like etc. to in the spreadsheet. And is it possible to automatically get refreshed.

    Hope i get the answer.


  32. Hello Ben, so much formula for fb pages and Instagram, but why nothing for the Fb groups ? Even when you are not yet a member of a Fb group you can see the information im trying to retrieve: name of the group, number of member , and Group description .
    Any genius willing to help me ?

  33. Hi,

    i tried implementing the code for facebook to get page views and total reach for my page but I am getting #REF error. What to do?

Leave a Reply

Your email address will not be published. Required fields are marked *