Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 如何使用rails查找google plus一个计数(不需要按钮和g';1图像)_Ruby_Ruby On Rails 3_Json_Curl_Google Plus One - Fatal编程技术网

Ruby 如何使用rails查找google plus一个计数(不需要按钮和g';1图像)

Ruby 如何使用rails查找google plus一个计数(不需要按钮和g';1图像),ruby,ruby-on-rails-3,json,curl,google-plus-one,Ruby,Ruby On Rails 3,Json,Curl,Google Plus One,我需要找到一个url的谷歌加一计数。 为了实现这一点,我遵循这一点 但是当我运行上面的代码时,它给了我以下错误 {"error"=>{"code"=>400, "message"=>"Invalid Value", "data"=>[{"domain"=>"global", "reason"=>"invalid", "message"=>"Invalid Value"}]}, "id"=>"p"} 当我跑的时候 curl -i -H 'Accep

我需要找到一个url的谷歌加一计数。 为了实现这一点,我遵循这一点

但是当我运行上面的代码时,它给了我以下错误

{"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"
}

以下代码在ruby中工作

    require 'curb'
    require 'json'
    hash =  {method: "pos.plusones.get",id: "p",params: {nolog: true, id: "http://www.tomanthony.co.uk/", source: "widget", userId: "@viewer", groupId: "@self"}, jsonrpc: "2.0", key: "p", apiVersion: "v1"} 
    result=(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)
    result=JSON.parse(result.body_str)
    count = result && result['result'] && result['result']['metadata'] && result['result']['metadata']['globalCounts'] && result['result']['metadata']['globalCounts']['count'] ? result['result']['metadata']['globalCounts']['count'].to_i : 0

我投了一个球来玩:
    require 'curb'
    require 'json'
    hash =  {method: "pos.plusones.get",id: "p",params: {nolog: true, id: "http://www.tomanthony.co.uk/", source: "widget", userId: "@viewer", groupId: "@self"}, jsonrpc: "2.0", key: "p", apiVersion: "v1"} 
    result=(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)
    result=JSON.parse(result.body_str)
    count = result && result['result'] && result['result']['metadata'] && result['result']['metadata']['globalCounts'] && result['result']['metadata']['globalCounts']['count'] ? result['result']['metadata']['globalCounts']['count'].to_i : 0