GoogleのカウントとURLの1を見つける必要があります。これを達成するために、私はこのブログをフォローしています
require 'curb'
require 'json'
hash = {method: "pos.plusones.get",id: "p",params: {nolog: true,id: "http://www.google.com",source: "widget",userId: "@viewer",groupId: "@self"},jsonrpc: "2.0",key: "p",apiVersion: "v1"}
result=JSON.parse((Curl::Easy.http_post("https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ", hash.to_json ) do |curl|
curl.headers['Accept']='application/json'
curl.headers['Content-Type']='application/json'
curl.headers['Api-Version']='2.2'
end
).body_str)
p result
count = result && result['result'] && result['result']['metadata'] && result['result']['metadata']['globalCounts'] && result['result']['metadata']['globalCounts']['count'] ? result['result']['metadata']['globalCounts']['count'] : 0
count ? count : 0
しかし、上記のコードを実行すると、次のエラーが発生します
{"error"=>{"code"=>400, "message"=>"Invalid Value", "data"=>[{"domain"=>"global", "reason"=>"invalid", "message"=>"Invalid Value"}]}, "id"=>"p"}
私が走るとき
curl -i -H 'Accept: application/json' -H 'Content-type: application/json' -X POST -d "{\"method\":\"pos.plusones.get\",\"id\":\"p\",\"params\":{\"nolog\":true,\"id\":\"http://www.google.com\",\"source\":\"widget\",\"userId\":\"@viewer\",\"groupId\":\"@self\"},\"jsonrpc\":\"2.0\",\"key\":\"p\",\"apiVersion\":\"v1\"}" 'https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ'
私は得る
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Date: Wed, 12 Dec 2012 11:52:58 GMT
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
Transfer-Encoding: chunked
{
"error": {
"code": 400,
"message": "Invalid Value",
"data": [
{
"domain": "global",
"reason": "invalid",
"message": "Invalid Value"
}
]
},
"id": "p"
}