Here is the code. Even if I drop it down to 100 results, but the 8th
or 9th query it errors out again with a timeout.
as = new AnalyticsService("gaExportAPI_acctSample_v1.0");
as.setConnectTimeout(10000);
as.setReadTimeout(10000);
System.out.println("Version: " + as.getVersion());
String baseUrl = "
https://www.google.com/analytics/feeds/data";
DataQuery query;
//------------------------------------------------------
// Client Login Authentication
//------------------------------------------------------
try {
as.setUserCredentials(userStr, pass);
} catch (AuthenticationException e) {
System.err.println("Error : " + e.getMessage());
return;
}
try {
query = new DataQuery(new URL(baseUrl));
} catch (MalformedURLException e) {
System.err.println("Malformed URL: " + baseUrl);
return;
}
// TODO parse passed URL to use Query tool
query.setIds("ga:" + profID);
query.setDimensions("ga:landingPagePath");
query.setMetrics("ga:entrances,ga:bounces");
query.setSort("-ga:entrances");
query.setFilters("ga:medium==organic");
query.setStartDate("2009-05-01");
query.setEndDate("2009-05-21");
/* set inside getPageResults
query.setMaxResults(maxNum);
query.setStartIndex(curPage);
*/
// Send our request to the Analytics API and wait for the results
to come back
try {
ArrayList<DataFeed> feedList = getPageResults(new
ArrayList<DataFeed>(), query, curPage, maxNum);
/* Object dataArray[] = feedList.toArray();
for(int i=0;1<dataArray.length;i++) {
outputFeedData((DataFeed) dataArray[i]);
}
*/
}catch (Exception e) {
System.err.println("Error trying to retrieve feed: " +
e.getMessage());
e.printStackTrace();
}
//end of doGet
}
public ArrayList<DataFeed> getPageResults(ArrayList<DataFeed> theList,
DataQuery query, int curPage, int maxNum) throws Exception {
DataFeed feed;
query.setMaxResults(maxNum);
query.setStartIndex((curPage-1)*maxNum+1 );
URL url = query.getUrl();
//URL url = new URL(reqURL);
System.out.println("URL: " + url.toString());
try {
feed = as.getFeed(url, DataFeed.class);
theList.add(feed);
System.out.println("Feed created # "+ theList.size());
System.out.println("Total Results "+ feed.getTotalResults());
if (curPage <= Math.floor(feed.getTotalResults()/maxNum+1)) {
getPageResults(theList, query, curPage+1, maxNum);
}
} catch (IOException e) {
System.err.println("Network error trying to retrieve feed: " +
e.getMessage());
e.printStackTrace();
return null;
} catch (ServiceException e) {
System.err.println("Analytics API responded with an error
message: " + e.getMessage());
return null;
}
return theList;
}
On Sep 4, 9:40 pm, Nick wrote:
> Can you share the query you are using?
>
> our API usually returns in < 10s for a 1000 row query.
>
> -Nick
>
> On Sep 4, 3:51 am, Spanishgringo wrote:
>
> > No luck. Ten second timout still happening on almost any new report
> > even when max results is 1000 records. The problem I think is more in
> > the calculation time for Analytics rather than the time to recevie the
> > xml response.
>
> > I think option 2 will be the only solution for a functional Java App
> > Engine app that uses Analytics.
>
> > I will gladly test any thing that you guys want to try to develop.
>
> > Michael
>
> > On Sep 4, 9:20 am, Spanishgringo wrote:
>
> > > Fantastic! I can't wait to try it out now. Thanks.
>
> > > On Sep 3, 11:58 pm, Nick wrote:
>
> > > > App Engine version 1.2.5 has just been released:
http://googleappengine.blogspot.com/2009/09/app-engine-sdk-125-releas...
>
> > > > You now can increase the URLFetchtimeoutto 10 seconds:
http://code.google.com/appengine/docs/java/urlfetch/overview.html#Req...