首页 > 解决方案 > javascript (2020) 中没有令牌的 Twitter 关注者计数?

问题描述

我问这个是因为以前的答案已经过时了。

我需要获取 twitter 关注者数量,理想情况下不使用 php 和/或 API 令牌。此代码返回错误:

  var twitter_username = 'billgates';
    
    $.ajax({
      url: "https://cdn.syndication.twimg.com/widgets/followbutton/info.json?screen_names=" + twitter_username,
      dataType: 'jsonp',
      crossDomain: true
    }).done(function(data) {
      console.log(data[0]['followers_count']);
    }).fail(function(data) {
   console.log(data);
  });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script>

返回的错误如下:

   (index):1 Refused to execute script from 'https://cdn.syndication.twimg.com/widgets/followbutton/info.json?screen_names=billgates&callback=jQuery112406752686864999666_1594556812284&_=1594556812285' because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled.

尽管从浏览器直接访问 url 确实会返回 json 文件。

如果没有 api,它是否可以修复或目前无法获得关注者数量?

标签: javascriptjqueryapitwitter

解决方案


推荐阅读