views:

36

answers:

1

I'm trying to use the garb gem to access data from the Google analytics API and find that http requests using garb work just fine from a Linode account, but are refused from home (Comcast). Is Google rejecting some kinds of http requests from certain ISPs, or am I just doing something wrong? Simple example is below:

require 'garb'

Garb::Session.login('[email protected]', 'XXXXXX')
@profile = Garb::Profile.all.first
@report = Garb::Report.new(@profile)
@report.metrics :visits
puts @report.results

This give => [#<OpenStruct visits="21">] on my Linode, but the exact same thing run from my home ISP gives:

Garb::DataRequest::ClientError: "<errorsxmlns=.........

Which is raised here in garb:

def send_request
  response = if @session.single_user?
    single_user_request
  elsif @session.oauth_user?
    oauth_user_request
  end

  raise ClientError, response.body.inspect unless response.kind_of?(Net::HTTPSuccess)
  response
end

The initial session login works just fine from both IPs. The error is only thrown when results are requested. Is there anything I can do to fix this? I haven't (yet) verified that I get exactly the same behavior going through clientlogin/data requests by hand. I'm pretty convinced it is not a gem issue, but an IP-related one--perhaps something to do with Google web services quota policies--but I'm willing to entertain all possible solutions.

Thanks, Orion

A: 

You've probably made too many calls to google in a short space of time. I haven't seen it happen with Garb, but I've seen it happen when using an API to scrape search results pages. Google notices and flags your IP. Try browsing to google.com and running a normal google search from the ip that's blocked, you'll probably be required to enter a captcha. They probably block API calls from that IP at this stage, you'll get cleared eventually after a few days I think.

Jeremy
I've used garb maybe a dozen times so far--only by hand. Google's quota is 10,000 per day as documented [here](http://code.google.com/apis/analytics/docs/gdata/gdataDeveloperGuide.html#quota). I'm not even close. Normal search or analytics access from my machine through google's sites is fine with no captcha.
Orion
Hmm, well if it's not that, I'm pretty much out of ideas. I assume you've compared ruby versions, and gem versions between the two computers?
Jeremy
I'm running ruby 1.8.7 on the mac (garb fail) and ruby 1.9.1 on the linode (garb success). I can try and upgrade the Mac and see if anything changes.
Orion
Yeah, that's certainly an avenue to check. I'd recommend using rvm (http://rvm.beginrescueend.com/) which lets you install and switch between multiple ruby versions on your local development machine if you don't want to touch tour working ruby install.
Jeremy
Thanks! Looks like a very useful tool to have around.
Orion