Fosome / garb

A Ruby wrapper for the Google Analytics API
http://www.viget.com/extend/
655 stars 89 forks source link

account.profiles seems to be returning a "invalidRequestUri" #110

Open brunogh opened 12 years ago

brunogh commented 12 years ago

It seems that the following code stopped working on account.profiles call. Not sure if it is a temporary Google issue, but noticed today.

def accounts_and_profiles_summarized
begin
      ga_profiles = []
      session = Garb::Session.new
      session.access_token = get_oauth_access_token
      accounts = Garb::Management::Account.all(session)
      accounts.each do |a|
        account = OpenStruct.new(:name => a.name, :profiles => [])
        a.profiles.each do |p|
          account.profiles << OpenStruct.new(:title => p.title, :ua_id => p.web_property_id)
        end
        ga_profiles << account
      end
      ga_profiles
    rescue => e
      p e
    end
end
- GAClient raises error at accounts_and_profiles_summarized:75: "<errors xmlns='http://schemas.google.com/g/2005'><error><domain>GData</domain><code>invalidRequestUri</code><internalReason>Invalid request URI</internalReason></error></errors>"
pedrobachiega commented 12 years ago

If you request Garb::Management::Account.all, the entities will have the full url at path param, like "https://www.googleapis.com/analytics/v2.4/management/accounts/123" when it is just to be "/accounts/123"

Seems that this is beeing caused by Management API v2.3 Forwarding http://groups.google.com/group/google-analytics-api-notify/browse_thread/thread/656aa688a733d5ff

pedrobachiega commented 12 years ago

What you could do as workaround is:

accounts = Garb::Management::Account.all(session)
      accounts.each do |a|
        account = OpenStruct.new(:name => a.name, :profiles => [])
        a.path.gsub!("https://www.googleapis.com/analytics/v2.4/management", '')
        a.profiles.each do |p|
          account.profiles << OpenStruct.new(:title => p.title, :ua_id => p.web_property_id)
        end
        ga_profiles << account
      end