Pregunta

I am trying to pull data from my Google+ API, using this script:

require 'open-uri'
require 'json'

google_api_key = 'put your google api key here'
page_id = '105672627985088123672'

data = open("https://www.googleapis.com/plus/v1/people/#{page_id}?key=#{google_api_key}").read    
obj = JSON.parse(data)

puts obj['plusOneCount'].to_i

However, I keep getting this error:

/Users/xng/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/open-uri.rb:346:in `open_http': 403 Forbidden (OpenURI::HTTPError)
    from /Users/xng/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/open-uri.rb:769:in `buffer_open'
    from /Users/xng/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/open-uri.rb:203:in `block in open_loop'
    from /Users/xng/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/open-uri.rb:201:in `catch'
    from /Users/xng/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/open-uri.rb:201:in `open_loop'
    from /Users/xng/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/open-uri.rb:146:in `open_uri'
    from /Users/xng/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/open-uri.rb:671:in `open'
    from /Users/xng/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/open-uri.rb:33:in `open'
    from gplus.rb:8:in `<main>'

I am not sure what is wrong here, any help would be great.

¿Fue útil?

Solución 2

Have to regenerate the API key.

Otros consejos

The problem looks like your google API key doesn't match the one that google have in their servers. So you need to make sure that you are using the right key. is it a private or free service ?

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top