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".
Not available via public API yet.
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.
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"
}
]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With