title: Saving photos from instagram api calls to Postgresql?
body: <p>So I wanted to create an app that makes a get request to the instagram api and grabs a users picture feed WHILE saving the url's of the photos to my postgresql database automatically. I'm assuming it's possible but am having a hard time figuring out how to go about it. I've got the picture feed coming out ok but saving to my DB is where I fail. Here is my instagram controller:</p>
  
  <pre><code>class InstagramController &lt; ApplicationController 
  
  before_action :set_ig_acc_code, only: [:feed, :search]
  
  def instagram
      # Find the access token
      res = HTTParty.post("https://instagram.com/oauth/access_token/",
       {body:{client_id: ENV["IG_CLIENT_ID"],
        client_secret: ENV["IG_CLIENT_SECRET"],
        grant_type:'authorization_code',
        redirect_uri:'http://localhost:3000/instagram',
        code: params[:code]}})
      redirect_to feed_path(acc_token: res.parsed_response["access_token"])
  end
  
  def feed
      # Show a feed of pictures
      if params[:user_id] # For a given user
          @feed = HTTParty.get("https://api.instagram.com/v1/users/" + URI::escape(params[:user_id]) + "/media/recent?access_token=" +
          @acc_token)
      else    # This user's folks they follow
          @feed = HTTParty.get("https://api.instagram.com/v1/users/self/feed?access_token=" +
          @acc_token)
      end
  end
  
  def search
      # Search users
      @url = "https://api.instagram.com/v1/users/search?q=" + URI::escape(params[
          :search][:query]) + "&amp;access_token=" +
       params[:acc_token]
      @results = HTTParty.get(@url)
  end
  
  private
      def set_ig_acc_code
          @acc_token = params[:acc_token]
      end
  
  end
  </code></pre>
  
  <p>Maybe I should make a photo model with a URL field and save them as they load through my feed somehow??? I'm banging my head against the wall on this one. Thanks in advance.</p>