tto8459 / r-google-analytics

Automatically exported from code.google.com/p/r-google-analytics
0 stars 0 forks source link

401 Unathorized authError #4

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
RGoogleAnalytics has stopped working due to changes in GA API. Whenever you 
execute a query it raises the error:

Error in GetDataFeed(query.builder$to.uri()) : 401 Unauthorized 
 authError Invalid Credentials

Apparently, now you juste append an API key to the query in the new GA API.

Original issue reported on code.google.com by xavier.g...@gmail.com on 3 Aug 2012 at 10:37

GoogleCodeExporter commented 8 years ago
Looking into an overhaul of the package to accommodate the new API call, 
security updates with passwords and documentation.

Original comment by michael....@gmail.com on 9 Aug 2012 at 7:26

GoogleCodeExporter commented 8 years ago
I think it would be worth it to move to the v3 (OAuth) style logins... but 
that's a more comprehensive change... especially because it moves the data 
interface to JSON as well.

I ended up creating a set of scripts to do that and would love to contribute 
where I can to RGoogleAnalytics.

Theo

Original comment by munkey...@gmail.com on 13 Aug 2012 at 3:29

GoogleCodeExporter commented 8 years ago
Hi Theo,

Thanks for the interest in this project, a little history around this
package.
It was created when myself and a couple of others worked @google and we did
this as a side project, however, i have since left and the other two
gentleman have tight time constraints and so this is why the package has
had little / no maintenance.

I dont really want to see this package die as i think its quite cute and
pretty helpful.

In the short term, there are 3 fixes that need to be made:

1.
The account feed:
https://www.google.com/analytics/feeds/accounts/defaultis about to go
away.
So the method > GetProfileXML
needs to be removed.

2.
The endpoint for data has changed:
from: https://www.google.com/analytics/feeds/data
to: https://www.googleapis.com/analytics/v2.4/data

3.
also we now require users to register using the API and they will need to
append a key to each query they make from our API.
The parameter looks like this:
&key=API_key

I very much agree that using the OAuth method would be much more preferable
but i fear i will not have the time to do this.
If you are volenteering for this job, (i'd be most grateful) we can rebuild
the package and with this feature and hopefully this time release to CRAN.
Previously the XML and RCurl packages were linux specific and so the
package wouldnt pass tests for Windows

Mike

Original comment by michael....@gmail.com on 13 Aug 2012 at 3:39

GoogleCodeExporter commented 8 years ago
Hey Mike,

Yes I too am an ex-googler (technically I got "bought" into Google via
DoubleClick),

I would love to help out with this project.  I used it quite a bit for a
while and hope to keep on using it (even presented how to use it to a local
R user group:
http://www.youtube.com/watch?v=yg9-CEzHElg&feature=player_embedded) .  So
rather than write my own special version of RGoogleAnalytics why not bring
some of the changes into the existing one right?

Yeah I'd love to see this on CRAN too...

Anyways, I'm up for working on the OAuth part of it...actually it's all
written I would just need to put it into the package with the existing code.

Just let me know where the project files are and how I should access them...

Theo

Original comment by munkey...@gmail.com on 13 Aug 2012 at 3:53

GoogleCodeExporter commented 8 years ago
We kept all files in Mondrian, i'll talk to Nick about the possibility of
porting this github or something similar.
In the meantime email directly and we can take this offline and work out a
quick way of solving this to get it working again ASAP

Mike

Original comment by michael....@gmail.com on 13 Aug 2012 at 4:09

GoogleCodeExporter commented 8 years ago
I think code.google.com has an SVN feature on it... I'd be up for using that 
directly if we can figure that out (Github is fine too).

I can't seem to figure out how to send you an email directly through this forum 
so shoot me an email if you can get access to my full email address through 
your site ownership.

Theo

Original comment by munkey...@gmail.com on 13 Aug 2012 at 4:44

GoogleCodeExporter commented 8 years ago
I've been using this package since Theo demonstrated it a few months ago at the 
Denver R User Group. I tried editing the end point and API key following Mike's 
comments above:

     from:
          https://www.google.com/analytics/feeds/data?
     to:
          https://www.googleapis.com/analytics/v2.4/data? .... &key=<MY API KEY>

This returned a 401:
     <?xml version="1.0" encoding="UTF-8"?><errors xmlns="http://schemas.google.com/g/2005"><error><domain>GData</domain><code>required</code><location type="header">Authorization</location><internalReason>Login Required</internalReason></error></errors>

I made a copy of the QueryBuilder.R file, edited the base uri on line 677, 
appended my api key just before the return on line 698:
     uri <- paste(uri, "&key=", "<MY API KEY>", sep = "")

... and then overwrote the original function:
     insertSource('QueryBuilderModified.R')

It looks like additional tweaks are necessary to make the authentication work ~ 
unless I made a stupid mistake.

Cheers,

Alex

Original comment by alexwool...@gmail.com on 13 Aug 2012 at 5:51

GoogleCodeExporter commented 8 years ago
I guess you guys are hardly working on this, is any help needed? A git 
repository would be appreciated in case you would need me to contribute. 

Thank you
Jan

Original comment by jh.horn...@gmail.com on 15 Aug 2012 at 10:14

GoogleCodeExporter commented 8 years ago
Hi Alex, 
Perhaps this thread will help you: 
https://groups.google.com/forum/?fromgroups#!topic/google-analytics-data-export-
api/ACj9Nlg_E20%5B1-25%5D 

Original comment by jennalee...@gmail.com on 15 Aug 2012 at 10:52

GoogleCodeExporter commented 8 years ago
Thank you, Jenna. That worked perfectly.

Alex

Original comment by a...@arw.is on 16 Aug 2012 at 3:02

GoogleCodeExporter commented 8 years ago
Hey all,  thought I'd post an example of using Oauth to do the token exchange 
with GA in case anyone just wanted to switch over to it.  I believe 
RGoogleAnalytics will eventually be updated with this...  but in any case See 
the example in this git repository. 

https://github.com/greentheo/ROAuthSamples

Original comment by munkey...@gmail.com on 23 Aug 2012 at 11:39

GoogleCodeExporter commented 8 years ago
I have been pushing for new info on this package on the Google Groups thread 
mentioned before, and it seems to have some interest (as some other people are 
trying to hack it out to get it to work for them), but it definitely lack some 
coordination.

greentheo put forward a git for the OAuth 2 authentication procedure, and 
JerryWho forked the original package code to update the api version from v2.3 
to v2.4.

I asked JW to use his git repository as the reference for contributing new 
code. What do you think?

I also asked (and ask you) if it would not be better to move up to GA api v3. 
It makes the whole XML parsing code obsolete, AFAICT, but maybe it would be the 
best way to go.

How about getting this package in CRANtastic shape? I am pretty sure many R 
folks out there are really in need of a good tool to get all their GA goodies 
into their data torturing routines ;)

Anybody?

Original comment by chirurgi...@gmail.com on 7 Sep 2012 at 9:56

GoogleCodeExporter commented 8 years ago
Oh, yes, I forgot to add (though I wrote it on the other thread): I've been 
trying to get the scripts working with apiV3. It needs the rjson library 
(obviously). I haven't got it to work yet, because it implies the rewrite of 
several of the current (XML parsing) functions, but I've made some headway. So, 
I too would be interested to know where we can contribute code and exchange 
ideas on this project.

Original comment by chirurgi...@gmail.com on 7 Sep 2012 at 10:22

GoogleCodeExporter commented 8 years ago
Hi all. Since we really needed this library, I've had to recreate it myself.

I've used the procedure from https://github.com/greentheo/ROAuthSamples

And have added a Google Analytics integration:

https://github.com/skardhamar/ga-auth-data

I'm no expert at r-scripting, so please contribute and report bugs etc. 

Original comment by analytic...@gmail.com on 21 Sep 2012 at 10:51

GoogleCodeExporter commented 8 years ago
A new version of RGoogleAnalyics has been released on this site which should 
resolve the OAuth2 issues.

Original comment by michael....@gmail.com on 17 Feb 2013 at 11:06

GoogleCodeExporter commented 8 years ago
awesome!

Sincerely,

Ajay Ohri

Author-
R for Business Analytics
http://www.amazon.com/R-Business-Analytics-A-Ohri/dp/1461443423

Original comment by ohri2007 on 17 Feb 2013 at 11:19

GoogleCodeExporter commented 8 years ago

Original comment by michael....@gmail.com on 17 Feb 2013 at 4:46

GoogleCodeExporter commented 8 years ago
{ "error": { "errors": [ { "domain": "global", "reason": "internalError", 
"message": "Internal Error" } ], "code": 500, "message": "Internal Error" } } 

string URL = 
"https://www.googleapis.com/youtube/v3/activities?part=snippet&key=key";
string DATA = @"{'snippet': {'description': 'reply via 
api','channelId':'channelid'}}";
byte[] byteArray = Encoding.UTF8.GetBytes(DATA);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
request.Method = "POST";
request.UserAgent = "Google APIs Explorer";
request.ContentType = "text/json; charset=utf-8";
request.ContentLength = byteArray.Length;           
request.Headers[HttpRequestHeader.Authorization] = "Bearer access_token";       

using (Stream dataStream = request.GetRequestStream())
{
   dataStream.Write(byteArray, 0, byteArray.Length);
}
try
{
    WebResponse webResponse = request.GetResponse();
    using (Stream webStream = webResponse.GetResponseStream())
    {
       if (webStream != null)
       {
          using (StreamReader responseReader = new StreamReader(webStream))
          {
             string response = responseReader.ReadToEnd();
             Console.Out.WriteLine(response);
           }
         }
      }
    }
    catch (WebException ex)
    {
        using (WebResponse response = ex.Response)
        {                         
             using (Stream data = response.GetResponseStream())
             using (var reader = new StreamReader(data))
             {
                string Json = "apierror :" + reader.ReadToEnd();
                Response.Write(Json);
              }
           }

         }

Original comment by sudhir.k...@gmail.com on 12 Feb 2014 at 11:25

GoogleCodeExporter commented 8 years ago
It's a few years later and the same problem as resurfaced... any update in the 
works?

Original comment by jmillerl...@gmail.com on 10 Aug 2015 at 4:45

GoogleCodeExporter commented 8 years ago
This code base and all updates have been migrated to GitHub

https://github.com/Tatvic/RGoogleAnalytics

Please use this version for cutting edge

Or simply use from CRAN using install.packages for stable version

Original comment by michael....@gmail.com on 10 Aug 2015 at 4:49