How to use HTTPARTY to parse JSON api call from LinkedIN [closed]
-
15-10-2022 - |
質問
I'm using gem 'httparty' on my Rails 4 app and I'm a bit confused on the actual location and syntax of where to put the the lines of code that I've been reading. As of right now, it's in my controller and I'm trying to call it through the view which is connected to my controller via routes. Here is my controller below.
require 'httparty'
class StuffsController < ApplicationController
def index
count = JSON.parse(url = 'https://www.linkedin.com/countserv/count/share?url=' + url + '&format=json'
count = JSON.parse(HTTParty.get(url).body)["count"]
end
end
I read this documentation from http://www.techhoppers.com/blog/ruby-on-rails/how-to-parse-the-json-api-call-with-httpparty-in-ruby-on-rails/#comment-7 and I would like to know where I'm supposed to put these two lines of code.
response = HTTParty.get("http://example.com/call/httparty")
parsed_response = JSON.parse(response.body)
Any help would be appreciated.
正しい解決策はありません
所属していません StackOverflow