代码之家  ›  专栏  ›  技术社区  ›  Dan Mitchell

通过安全域从Instagram Gem中提取图像

  •  0
  • Dan Mitchell  · 技术社区  · 12 年前

    我正在使用Instagram gem从API获取信息,但我的浏览器控制台中出现错误,因为图像是以HTTP形式在HTTPS站点上传递的。

    看法

    <% instagram.each do |i| %>
        <li>
          <%= link_to i.link, :target => "_blank" do %>
              <%= image_tag i.images.standard_resolution.url %>
          <% end %>
        </li>
    <% end %>
    

    应用程序控制器

    def instagram Instagram.user_recent_media("xxxxxx", {:count => 6})
        rescue nil 
    end
    

    初始化器

    require "instagram"
    
    Instagram.configure do |config|
        config.client_id = "xxx"
        config.access_token = "xxx"
    end
    
    1 回复  |  直到 12 年前
        1
  •  1
  •   koosa    12 年前

    Instagram将通过http和https提供资产,因此只需调整URL即可。您可以使URL协议相对,以便始终使用正确的协议将图像加载到浏览器中。在您的视图中尝试以下操作:

    <%= image_tag i.images.standard_resolution.url.sub(/^https?\:/, '') %>