【问题标题】:How to retrieve video view count from Instagram API如何从 Instagram API 检索视频观看次数
【发布时间】:2016-02-28 18:29:46
【问题描述】:

Instagram 最近开始显示视频的观看次数。有没有办法从 API 中提取这些数据?

我通读了documentation,但找不到任何关于“查看”的信息,只有“喜欢”。

【问题讨论】:

    标签: instagram-api


    【解决方案1】:

    尚未通过公共 API 提供。

    【讨论】:

      【解决方案2】:

      我发现的唯一方法是使用诸如 Seleniuim 之类的浏览器自动化系统地抓取帖子的永久链接(使用一些逻辑处理格式,例如 5.6k 视图与 1,046 视图)并选择适当的元素。由于没有检测到 javascript,一个简单的 GET 请求不会产生所需的 DOM。

      在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
      

      PhantomJS驱动可以下载here.

      【讨论】:

        【解决方案3】:

        是的,您可以获得它,如果您的 facebook 和 instagram 帐户已关联并且您的 instagram 帐户有业务资料,请提出以下 GET 请求:

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

        您将收到以下格式的回复:

        {
          "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"
            }
          ]
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2014-08-12
          • 2017-03-26
          • 2015-06-20
          • 2013-07-21
          • 2011-03-20
          • 2019-04-28
          • 2023-03-17
          • 1970-01-01
          相关资源
          最近更新 更多