user2270029
user2270029

Reputation: 871

Parse JSON API Call with HTTParty in Ruby

I am trying to get the share count from this Linkedin API call using HTTParty in Rails, but it doesn't seems to properly be parsing and obtaining data. Why is that?

count = JSON.parse(HTTParty.get('https://www.linkedin.com/countserv/count/share?url=' + url + '&format=json')["count"]

Upvotes: 2

Views: 2404

Answers (1)

falsetru
falsetru

Reputation: 368964

You should use body attribute instead of the return value of the get (HTTParty::Response).

url = 'https://www.linkedin.com/countserv/count/share?url=' + url + '&format=json'
count = JSON.parse(HTTParty.get(url).body)["count"]
#                                   ^^^^^

Upvotes: 3

Related Questions