Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7501943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:42:05+00:00 2026-05-29T20:42:05+00:00

I am trying to build a quick hack that likes all the recent photos

  • 0

I am trying to build a quick hack that “likes” all the recent photos on instagram of a particular tag.

I have authenticated and used the JSON gem to turn the JSON from the API into a Ruby Hash like this:

def get_content (tag_name)

   uri = URI.parse("https://api.instagram.com/v1/tags/#{tag_name}/media/recent? access_token=#{@api_token}")

   http = Net::HTTP.new(uri.host, uri.port)
   http.use_ssl = true
   http.verify_mode = OpenSSL::SSL::VERIFY_NONE

   request = Net::HTTP::Get.new(uri.request_uri)

   json_output = http.request(request)
   @tags = JSON.parse(json_output.body)

end

This outputs a hash with arrays as keys nested like the original JSON ( ex. http://instagr.am/developer/endpoints/tags/)

I am trying to iterate over and retrieve all the “id”s of the photos.

However when I use each method:

@tags.each do |item| 
  puts item["id"]
end

I get an error:

instagram.rb:23:in `[]': can't convert String into Integer (TypeError)
from instagram.rb:23:in `block in like_content'
from instagram.rb:22:in `each'
from instagram.rb:22:in `like_content'
from instagram.rb:42:in `<main>'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T20:42:06+00:00Added an answer on May 29, 2026 at 8:42 pm

    instagram.rb:23:in `[]': can't convert String into Integer (TypeError)
    

    You’re getting this error because in puts item["id"], item is an Array, not a Hash, so Ruby tries to convert what you put between [] into an integer index, but it can’t because it’s a string ("id").

    This arises from the fact that json_output.body is a Hash. Take a second look at the example JSON response in the documentation:

    { "data" : [
        { "type"     : "image",
          // ...
          "id"       : "22699663",
          "location" : null
        },
        // ...
      ]
    }
    

    This whole structure becomes a single Hash with one key, "data", so when you call @tags.each you’re actually calling Hash#each, and since "data"‘s value is an Array when you call item["id"] you’re calling Array#[] with the wrong kind of parameter.

    Long story short, what you actually want to do is probably this:

    @tags = JSON.parse( json_output.body )[ "data" ]
    

    ..then @tags will be the Array you want instead of a Hash and you can iterate over its members like you wanted:

    @tags.each do |item| 
      puts item["id"]
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to build a quick overview that shows the upcoming calendar week. I
Question I'm trying to build a quick and easy ASP.NET page that redirects a
I am trying to build a quick application with Java/Hibernate that uses Google Maps
Trying to build a GUI application in Java/Swing. I'm mainly used to painting GUIs
Alright, here's what I'm trying to do. I'm attempting to write a quick build
I am trying to build a package (libnet) in Solaris and I found that
Quick overview: trying to build a gallery with a string from $_GET ('foo'), which
I have been trying to whip up a quick and dirty application. This application
I'm trying to build a quick administrative interface using the built in Windows.Forms PropertyGrid
I am trying to build a quick search box. it is basically a widget.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.