Blogger 提要帖子在不同站点上显示 CORS 错误

Blogger feed posts showing CORS Error on different site

参考 this answer of Google,我尝试通过 URL 使用我的 Feed 的 json 版本:https://[blog address].blogspot.com/feeds/posts/default?alt=json。我的博客设置为 public 模式,但它也抛出 CORS 策略。这是我使用的代码:

  <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>

<script>
var getJSON = function(url, callback) {
    var xhr = new XMLHttpRequest();
    xhr.open('GET', url, true);
    xhr.responseType = 'json';
    xhr.onload = function() {
      var status = xhr.status;
      if (status === 200) {
        callback(null, xhr.response);
      } else {
        callback(status, xhr.response);
      }
    };
    xhr.send();
};
getJSON('https://[blog].blogspot.com/feeds/posts/default?alt=json',
function(err, data) {
  if (err !== null) {
    alert('Something went wrong: ' + err);
  } else {
    alert('Your query count: ' + data.query.count);
  }
});
</script>

请尝试 alt=json-in-script

<script type="text/javascript">
function myFunction({feed}) {
  alert('Your query count: ' + feed.entry.length);
}
</script>
<script type="text/javascript" src="https://blog.blogspot.com/feeds/posts/default?alt=json-in-script&callback=myFunction"></script>