10

Instagram recently started showing view counts on videos. Is there a way to pull this data from the API?

I read through the documentation but I could not find anything about "Views" only "Likes".

Chris
  • 103
  • 1
  • 7

3 Answers3

4

Not available via public API yet.

Reza_Rg
  • 3,345
  • 7
  • 32
  • 48
3

The only way I've found is to systematically scrape posts' permalinks using browser automation like Seleniuim (with some logic handling the formatting e.g. 5.6k views vs 1,046 views) and picking out the appropriate element. A simple GET request doesn't yield the desired DOM due to the lack of javascript detected.

In python:

from bs4 import BeautifulSoup
from selenium import webdriver

def insertViews(posts):
    driver = webdriver.PhantomJS('<path-to-phantomjs-driver-ignoring-escapes>')
    views_span_dom_path = '._9jphp > span'

    for post in posts:
        post_type = post.get('Type')
        link = post.get('Link')
        views = post.get('Views')

        if post_type == 'video':
            driver.get(link)
            html = driver.page_source

            soup = BeautifulSoup(html, "lxml")
            views_string_results = soup.select(views_span_dom_path)
            if len(views_string_results) > 0:
                views_string = views_string_results[0].get_text()
            if 'k' in views_string:
                views = float(views_string.replace('k', '')) * 1000
            elif ',' in views_string:
                views = float(views_string.replace(',', ''))
            elif 'k' not in views_string and ',' not in views_string:
                views = float(views_string)
        else:
            views = None

        post['Views'] = views
    driver.quit()
    return posts

The PhantomJS driver can be downloaded here.

jpryda
  • 41
  • 1
  • 3
3

Yes you can get it, if you have your facebook and instagram accounts linked and your instagram account has a business profile, make following GET request:

https://graph.facebook.com/v3.0/instagram_video_id/insights/video_views

you will get response in this format:

{
  "data": [
    {
      "name": "video_views",
      "period": "lifetime",
      "values": [
        {
          "value": 123
        }
      ],
      "title": "Video Views",
      "description": "Total number of times the video has been seen",
      "id": "instagram_video_id/insights/video_views/lifetime"
    }
  ]
}
Rahul
  • 56
  • 9