0

I am trying to use the REST web services API from Google (Analytics) and I am getting a meaningless response instead of the expected data from Google Analytics.

Here is my request and the corresponding response:

GET /auth/analytics.readonly?ids=ga:12660456&start-date=2012-01-01&end-date=2012-02-02&metrics=ga:visits HTTP/1.1
Host: www.googleapis.com
Authorization: OAuth ya29.mytokenhere

HTTP/1.1 200 OK
status: 200
content-length: 18
x-xss-protection: 1; mode=block
content-location: https://www.googleapis.com/auth/analytics.readonly?ids=ga:12660456&start-date=2012-01-01&end-date=2012-02-02&metrics=ga:visits
x-content-type-options: nosniff
x-google-cache-control: remote-fetch
expires: Mon, 21 May 2012 19:52:57 GMT
server: GSE
via: HTTP/1.1 GWA
cache-control: private, max-age=0
date: Mon, 21 May 2012 19:52:57 GMT
x-frame-options: SAMEORIGIN
content-type: text/plain
-content-encoding: gzip

analytics.readonly

Can anyone please help?

Regards,

1 Answer 1

1

OAuth isn't performed by requesting the auth scope URL, like you seem to be doing. The only reason the Google's auth scopes are URLs at all are (AFAIK) so that they can be guaranteed to be globally unique.

More details about how to do OAuth 2.0 with Google here: https://developers.google.com/accounts/docs/OAuth2

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks. I am not sure I am following you... Do you mean I am using the wrong URL? I tried removing "auth" from the URL and it results in a 404.
What I mean is, the URL "googleapis.com/auth/analytics.readonly" is not meant to be retrieved by URL -- it is an identifier of what access you want to request. It might as well just be the string "analytics.readonly" because that's the only information it conveys. Make a request to https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/analytics.readonly&... as described in the docs I linked to get the authorization code, then access token you will need.
This is probably a more relevant doc than the one linked before: developers.google.com/accounts/docs/OAuth2WebServer -- remember that the analytics.readonly string is the scope you are requesting, so you will put it in the ?scope= URL parameter.
Success! It works with the following URL: https://www.googleapis.com/analytics/v3/data/ga?scope=https://www.googleapis.com/auth/‌​analytics.readonly&ids=ga:12660456&start-date=2012-05-21&end-date=2012-05-21&metrics=ga:visits,ga:pageviews
This isn't doing what you think it is. Just appending the ?scope= parameter to your requests won't do anything at all. In fact, this fails for me with a "Login Required" message, which indicates that the user is not authenticated. I would suggest learning about how OAuth 2.0 works first, then applying that to this situation. You can also play around with OAuth 2.0 at the OAuth 2.0 Playground: code.google.com/oauthplayground

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.