Hitachi Vantara Pentaho Community Forums
Results 1 to 2 of 2

Thread: Google Analytics Core API 2.4 access via http client

  1. #1
    Join Date
    Dec 2013
    Posts
    4

    Default Google Analytics Core API 2.4 access via http client

    Hello,

    I'm getting a bit pissed, because the solution is close, bute the answer from google still

    <ins>That’s an error.</ins>
    <p>The requested URL <code>/analytics/v2.4/data?ids=ga:xxxx&amp;start-date=2013-11-01&amp;end-date=2013-11-01&amp;metrics=ga:impressions&amp;key=yyyyyyy</code> was not found on this server. <ins>That’s all we know.</ins>
    "

    how do i really access the google core api 2.4 via a http client step?!

    stackoverflow.com/questions/10015282/how-to-get-access-to-google-analytics-data-api-using-pentaho-pdi-kettle-version

    this is close, but not properly working.

    Can anybody tell me where's the mistake??


    Thanks and cheers,

    Holger
    Last edited by Hol Ger; 01-07-2014 at 02:23 PM.

  2. #2
    Join Date
    Dec 2012
    Posts
    5

    Default

    I believe that you need to enable an authentication process before you submit the above URL. Tricky for a novice (like me). It's a part of the header that is sent along with this URL. The CURL command is the way to submit this properly to insert all relevant data to get it to work. That works in a Linux/Unix environment, but with Windows you need to install Cygwin.

    I was able to get Kettle to run a script through Cygwin (I'm on windows) using the module "Execute shell script" in a Transform with this in the Script tab: C:\cygwin\Cygwin.bat C:/cygwin/home/Administrator/test_ga_01.sh
    That combination (module: Execute Shell Script + cygwin pointing to a .sh file) has been really useful for accessing these HTTP services. Plus, you could de-bug the code by copying it line-by-line into a cygwin window to see the response.

    The test_ga_01.sh script file looks like this:

    *****************use the code below this line*********************
    #!/bin/bash

    USER_EMAIL="MY_GMAILACCOUNT@gmail.com" #Insert your Google Account email address here
    USER_PASS="MY_PASSWORD" #Insert your password here
    TABLE_ID="ga:MY_ACCOUNT_NUMBER" #Insert your table ID here (ie ga:1234)
    OUTPUTFILE="/cygdrive/d/cygwin/tmp/googletest_01.xml" #this is how cygwin determines the drive letter and directory. The d is drive d:

    googleAuth="$(curl --proxy INSERT_YOUR_PROXY_IP:INSERT_YOUR_PORT_NUMBER https://www.google.com/accounts/ClientLogin -s\
    -d Email=$USER_EMAIL\
    -d Passwd=$USER_PASS\
    -d accountType=GOOGLE\
    -d source=curl-dataFeed-v2\
    -d service=analytics\

    | awk /Auth=.*/)"

    feedUri="https://www.google.com/analytics/feeds/data\
    ?ids=$TABLE_ID\
    &start-date=2014-03-08\
    &end-date=2014-03-09\
    &dimensions=ga:dimension21,ga:dimension20,ga:dimension3\
    &metrics=ga:visitors,ga:visits,gaageviews\

    &sort=ga:dimension21\
    &max-results=100\
    &prettyprint=true\
    &output=json\
    &fields=columnHeaders(name,dataType)"

    curl --proxy INSERT_YOUR_PROXY_IP:INSERT_YOUR_PORT_NUMBER $feedUri -s -H "Authorization: GoogleLogin $googleAuth" -H "GData-Version: 2" -o "${OUTPUTFILE}"
    ****************use the code above this line***********************

    This returns an XML output to googletest_01.xml that you then need to parse (still trying to figure that out!). The output=json line may change this format, though. It still output to an xml format with this code.


    Make sure you use a good text editing package (e.g. Notepad++) to see all hidden characters. Ensure you have Unix line break standards (I had DOS configured while de-bugging and it didn't work as it inserted both Carriage return and Linefeed at the end of each line). Also ensure when you copy you don't have any space characters at the end of lines. The "| awk /Auth=.*/)"" line above still throws an error in Cygwin, but it still returns a value.
    This will send your email and password free and clear through the internet. Dangerous. I'm trying to determine how to encrypt it effectively.


    If anyone can figure out how to get the Google Analytics module to work through a proxy, please let me know. No amount of adjusting of the OS, java-console nor spoon.bat environment variables would allow authentication to the API. And, I've verified that the credentials work on a non-proxy-based system.

    --Joe

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.