0

I have followed the answer of this question. And this is what i have.

  def index
       $response = get_insta_feed
  end

  def get_insta_feed
    require "net/http"
    require 'net/https'
    require "uri"

    $tag = "test"
    uri = URI.parse("https://api.instagram.com/v1/tags/"+$tag+"/media/recent")
    uri.query = URI.encode_www_form(parameters)
    http = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    request = Net::HTTP::Post.new(uri.request_uri)
    http.request(request).to_json
  end

  private

  def parameters
    {
        "access_token" => "my access token here"
    }
  end

on my view page i just want to display the full json response first before parsing the data that i want to display so this:

<div>
  <%=$response%>
</div>

and this is what is displayed in my div:

{"server":["nginx"],"date":["Fri, 07 Nov 2014 06:13:34 GMT"],"content-type":["text/html; charset=utf-8"],"allow":["GET"],"content-language":["en"],"expires":["Sat, 01 Jan 2000 00:00:00 GMT"],"vary":["Cookie, Accept-Language"],"pragma":["no-cache"],"cache-control":["private, no-cache, no-store, must-revalidate"],"set-cookie":["csrftoken=e70981e518d478dd7362049f9ce89cc9; expires=Fri, 06-Nov-2015 06:13:34 GMT; Max-Age=31449600; Path=/","ccode=PH; Path=/"],"connection":["close"]}

What am I doing wrong?

Community
  • 1
  • 1
galao
  • 1,281
  • 8
  • 26
  • 50

1 Answers1

0

Please use instagram gem for the connection tasks to Instagram. For example you can use it as follows:

client = Instagram.client(:access_token => session[:access_token])
for media_item in client.tag_recent_media(tag_name)
   # Use the folowing fields... 
   # media_item.images.thumbnail.url
   # media_item.id
   # media_item.likes[:count]
end

For more information of the gem, please refer to its github page.

Малъ Скрылевъ
  • 16,187
  • 5
  • 56
  • 69