문제

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"]
도움이 되었습니까?

해결책

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"]
#                                   ^^^^^
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top