javascript - 无法从 Shopify 调用 instagram API

标签 javascript jquery shopify instagram-api instafeedjs

我正在尝试使用我的 shopify 网上商店中的 instagram API。我正在使用javascript。当我使用 jQuery 时,instagram 不会传回正确的 header 。

这是我的代码(调用已验证):

jQuery

$.getJSON( call, function( data ) {
  alert("sdfewsf");
}).error(function(jqXHR, textStatus, errorThrown) {
  console.log("error " + textStatus);
  console.log("incoming Text " + jqXHR.responseText);
});

这是我收到的错误:

XMLHttpRequest cannot load https://api.instagram.com/v1/tags/%7Btag-name%7D/media/recent?client_id=95d4426edafc476d9b76a5dacc4c12ca. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://www.99centrazor.com' is therefore not allowed access. The response had HTTP status code 404.

我也尝试过 instafeed.js,但它不起作用。

Instafeed.js

 var feed = new Instafeed({
  get: 'tagged',
  tagName: 'awesome',
  clientId: clientId
});
feed.run();

这会返回一个对象,但运行函数不起作用 --

Uncaught TypeError: Cannot read property 'appendChild' of null

有谁知道让这个东西起作用的方法吗?!?! 谢谢!

最佳答案

关于 instafeed.js,我将缩小对第二个问题的回答范围。

您看到的错误是由于 instafeed.js 在页面上找不到它的目标元素造成的。

要解决此问题,请确保您已输入 <div id="instafeed"></div>在您的页面上,并且您在页面完全加载后加载 instafeed.js:

$(document).ready(function() {
  var feed = new Instafeed({
    get: 'tagged',
    tagName: 'awesome',
    clientId: clientId
  });
  feed.run();
});

关于javascript - 无法从 Shopify 调用 instagram API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33287115/

相关文章:

javascript - 将 javascript 语法从 ids 更改为 classes

javascript - 如何在我的页面上的所有超链接上调用函数?

javascript - expo AsyncStorage 方法不是函数

jquery - 如何从轨道列表中动态更改 html 播放器 src

javascript - 为什么我的 forEach 循环不能处理 $ ('img' 返回的图像数组)?

javascript - 对 CoffeeScript 范围的误解

javascript - 如何使用 javascript 或 jQuery 删除或更改我的网址中的 .html 扩展名?

javascript - 通过 id jquery 将文本转换为链接

ios - 更新购物车中的产品数量(而非数量) - Shopify Mobile Buy SDK

javascript - 如何使用 html select 元素的值对 Shopify Liquid 中的集合进行排序