Trying to take data from google analytics and print
Hi,
I am trying to program a basic code to take information from google analytics and print it out. I wrote some code, whats wrong. (user/pass) removed for privacy reasons.
I am trying to make it all occur in one class for now (Its the beta version to make sure I can download information and use it before I start the real program). I just want to take information and print it out. I know the table id isn't set, but the program won't compile:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at xyz.xyzStart.main(xyzStart.java:96)
--
also can someone explain how to connect to google analytics and get information. I read googles help, and api but I'm still stuck
------
[highlight = java]
package xyz;
import com.google.gdata.client.analytics.AnalyticsService ;
import com.google.gdata.client.analytics.DataQuery;
import com.google.gdata.data.analytics.Aggregates;
import com.google.gdata.data.analytics.DataEntry;
import com.google.gdata.data.analytics.DataFeed;
import com.google.gdata.data.analytics.DataSource;
import com.google.gdata.data.analytics.Dimension;
import com.google.gdata.data.analytics.Metric;
import com.google.gdata.data.analytics.Segment;
import com.google.gdata.util.AuthenticationException;
import com.google.gdata.util.ServiceException;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
public class xyzStart {
private static final String id= "-";
private static final String Pass = "-";
public DataFeed feed;
/**
* trial run of program
*/
public xyzStart(){
// try{
String started = "the program has started";
System.out.println(started);
dataFeedSet();
printFeedData();
// }
//catch{
// }catch{
// }catch{
}
/**
* Need to edit later, basics to be used/tinkered with
*
*/
public void dataFeedSet(){
AnalyticsService as = new AnalyticsService("xyz.com");
//authorization
as.setUserCredentials(id, Pass);
// GA Data Feed query uri.
String baseUrl = "https://www.google.com/analytics/feeds/data";
DataQuery query = new DataQuery(new URL(baseUrl));
query.setIds(TABLE_ID);
query.setDimensions("ga:source,ga:medium");
query.setMetrics("ga:visits,ga:bounces");
query.setSegment("gaid::-11");
query.setFilters("ga:medium==referral");
query.setSort("-ga:visits");
query.setMaxResults(5);
// allow user to preset? or alter?
query.setStartDate("2011-06-01");
//latest date solution? have user enter?
query.setEndDate("2008-10-31");
URL url = query.getUrl();
System.out.println("URL: " + url.toString());
// Send our request to the Analytics API and wait for the results to
// come back.
feed = as.getFeed(url, DataFeed.class);
}
public void printFeedData(){
System.out.println("\n-------- Important Feed Information --------");
System.out.println(
"\nFeed Title = " + feed.getTitle().getPlainText() +
"\nFeed ID = " + feed.getId() +
"\nTotal Results = " + feed.getTotalResults() +
"\nSart Index = " + feed.getStartIndex() +
"\nItems Per Page = " + feed.getItemsPerPage() +
"\nStart Date = " + feed.getStartDate().getValue() +
"\nEnd Date = " + feed.getEndDate().getValue() +
"\nContains Sampled Data = " + feed.getContainsSampledData().getValue().toString( ));
}
public static void main(String[] args) {
}
}
[/ highlight]