【问题标题】:JSON::ParserError in HomeController#indexHomeController#index 中的 JSON::ParserError
【发布时间】:2016-02-11 20:42:32
【问题描述】:

我正在学习 instagram API,由于 Instagram 刚刚更改了他们的身份验证,所以这很复杂,所以还没有很多关于它的文档。

这与instagram gem JSON::ParserError in SessionController#index 基本上是相同的问题(我什至遵循相同的教程)但是(a)该解决方案是关于用户 ID - 我不是针对用户,而是针对一般公共提要,并且( b)它来自身份验证更改之前,我很确定这是某种身份验证问题。

这是我的控制器

class HomeController < ApplicationController
  def index
    @popular = Instagram.media_popular
  end
end

初始化程序/instagram.rb

require "instagram"
   Instagram.configure do |config|
   config.client_id = "MY CLIENT ID"
   config.access_token = "MY ACCESS TOKEN"
end

views/home/index.html.erb

<h1>Instagram Lookup</h1>
  <% @popular.each do |popular| %>
  <div class="col-sm-12 col-md-4">
    <div class="thumbnail">
      <%= image_tag popular.images.low_resolution.url %>
      <div class="caption">
        <%= popular.user.username %>
      </div>
    </div>
  </div>
<% end %>

我做错了什么? 这是 Rails 4.2.3、Ruby ruby​​ 2.1.1p76 和 Instagram 1.1.6

【问题讨论】:

    标签: ruby-on-rails instagram


    【解决方案1】:

    确保在使用正确的值初始化client_idaccess_token 后重新启动了服务器?

    此外,您需要将client 连接到 API(根据 gem 的官方文档),然后通过该 client 对象检索 media_popular

    比如:

    client = Instagram.client(:access_token => session[:access_token])
    @popular = client.media_popular
    

    更多参考,请点击here

    【讨论】:

      猜你喜欢
      • 2018-01-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-16
      • 1970-01-01
      • 1970-01-01
      • 2010-11-18
      • 1970-01-01
      相关资源
      最近更新 更多