google-sheetsgoogle-sheets-formulasocial-media

How do I use importxml to pull a still/cover photo from an instagram photo?


I'm creating a report on social media performance. I have the link to the post in a cell and I'm using importxml to pull the photo/video so people know which post i'm referencing. Here's the formula I'm using:

=IMAGE(IMPORTXML(D63,"//meta[@property='og:image']/@content"))

However, the image is cut in half on the instagram posts - but looks great on the tiktok posts. I can't figure out what the xpath should be instead after experimenting with inspecting element on instagram & playing around with different xpaths. Hoping someone here might have an answer!

I get a a photo that's cut half way, almost as if it didn't finish loading.


Solution

  • Here's one approach:

    =image(substitute(A2,"reel","p")&"media/?size=l")
    

    enter image description here