ip2k / google-api-ruby-client

Automatically exported from code.google.com/p/google-api-ruby-client
Apache License 2.0
0 stars 0 forks source link

Working Example of Service Account application accessing Analytics API #44

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. NA
2.
3.

What is the expected output? What do you see instead?
NA

What version of the product are you using? On what operating system?

Please provide any additional information below.
It would be great to have a working example of a Service Account application 
accessing Google Analytics API, public/private auth and all.

Original issue reported on code.google.com by Winderme...@gmail.com on 15 Jun 2012 at 12:16

GoogleCodeExporter commented 9 years ago

Original comment by bobaman@google.com on 15 Jun 2012 at 9:22

GoogleCodeExporter commented 9 years ago
i agree 10000%.

Using the examples in the README, lead me to the code, which lead me to adding 
`pry`, which lead me to an error in Google::APIClient::Method line 107 (108 
after i added pry).

Basically reading the comments in deep google , i understood you needed to do 
something like this:

~ bundle exec google-api irb oauth-2-login 
--scope='https://www.googleapis.com/auth/analytics.readonly' 
--client-id='blahaddyoursehere.apps.googleusercontent.com' 
--client-secret='secret-codedstuff'
1.9.3p125 :001 > blah = $client.discovered_api("analytics", "v3")
 => #<Google::APIClient::API:0x3fd009016a6c ID:analytics:v3> 
1.9.3p125 :002 > method = Google::APIClient::Method.new(blah.name, 
blah.method_base.to_s, "analytics.data.ga.get", 
$client.discovery_document("analytics", "v3"))
 => #<Google::APIClient::Method:0x3fd009025aa8 ID:analytics:v3> 
1.9.3p125 :003 > $client.execute(method, {})

NoMethodError: undefined method `join' for 
#<Google::APIClient::Method:0x3fd009025aa8 ID:analytics:v3>

See, just doing $client.execute('analytics.data.ga.get', {}) returned nothing 
but errors, that led me to this current error that I think line 107 is wrong... 
maybe you meant URI::Template.join

Original comment by phi...@ingraminternet.com on 26 Jun 2012 at 10:51

GoogleCodeExporter commented 9 years ago

Original comment by bobaman@google.com on 23 Jul 2012 at 7:37

GoogleCodeExporter commented 9 years ago

Original comment by bobaman@google.com on 23 Jul 2012 at 7:38

GoogleCodeExporter commented 9 years ago
AFAIK, service accounts aren't supported with analytics API. Will add analytics 
sample and a service accounts sample, but won't be in the same one. Service 
accounts is currently limited to APIs like storage & prediction.

Original comment by sba...@google.com on 23 Jul 2012 at 9:44

GoogleCodeExporter commented 9 years ago
As a stopgap until formal documentation shows up, here's a quick blog post I 
wrote up for using SA auth with Google analytics:

Working example code:
http://ominian.com/2012/07/12/service-accounts-with-ruby-and-the-google-api-clie
nt/

And a complete Gist file here https://gist.github.com/3166610

It's a little slow, but it does work.  I would use the Analytics explorer tool 
here http://ga-dev-tools.appspot.com/explorer/ to build your queries and then 
go from there.

Original comment by ward.dav...@gmail.com on 23 Jul 2012 at 10:23

GoogleCodeExporter commented 9 years ago
Ah, inviting the service account through analytics works for auth :)

Original comment by sba...@google.com on 23 Jul 2012 at 10:55

GoogleCodeExporter commented 9 years ago
Hehe, that's actually pretty clever.

Original comment by bobaman@google.com on 24 Jul 2012 at 12:29

GoogleCodeExporter commented 9 years ago
Added to the samples repository.

Original comment by sba...@google.com on 24 Jul 2012 at 9:56

GoogleCodeExporter commented 9 years ago
Might want to mention in the sample to add the SA email address to the desired 
Google analytics profile to allow for access.

Original comment by ward.dav...@gmail.com on 25 Jul 2012 at 4:32