GooglePlus Counter Ruby

Nicht zuletzt nur für Newshype zähle ich gerne die Statistiken, die man bei den gängigen Netzwerken so vorfinden kann. Da Google+ noch keine offizielle API anbietet, habe ich für Ruby eine Möglichkeit gefunden. Inspiration und Starthilfe war dabei dieser PHP-Scraper.

Den Code gibt es bei github oder hier:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
require 'curb'
require 'json'
def count_gplus(url)
jsonstring = '[{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"' + url +'","source":"widget","userId":"@viewer","groupId":"@self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}]'
 
c = Curl::Easy.http_post("https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ", jsonstring) do |curl|
curl.headers['Accept'] = 'application/json'
curl.headers['Content-Type'] = 'application/json'
curl.headers['Api-Version'] = '2.2'
end
 
response = JSON.parse(c.body_str)
if response[0]['error'] == nil
return false
else
return count = response[0]['result']['metadata']['globalCounts']['count'].round
end
end
#simple: count_gplus("url")

Schreibe den ersten Kommentar.

All Felder sind optional.