Google Analytics API with Objective c, Part two

by roberto.vega 16. October 2009 15:45

Well it is time for part two. Part one was easy and the second part is easy as well.
Now that we got the authentication token we can get analtyics data.
The data we are getting is the accounts and profiles for analytics:

NSURL *urlAccount = [NSURL URLWithString:@"https://www.google.com/analytics/feeds/accounts/default"];

NSString* param = [NSString stringWithFormat:@"GoogleLogin auth=%@",authString]; 
NSMutableURLRequest *req = [[NSMutableURLRequest alloc] initWithURL:urlAccount];
[req setHTTPMethod:@"GET"];
[req addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[req setValue:param forHTTPHeaderField: @"Authorization"];
[req addValue:@"Authorization" forHTTPHeaderField:param];

NSHTTPURLResponse *res;
NSError *err;
NSData *data = [NSURLConnection sendSynchronousRequest:req returningResponse:&res error:&err];

[req release];
return data;

Finally u get a NSData. I personal use libxml2 for parsing the xml data and XPath queries. Check out http://cocoawithlove.com/2008/10/using-libxml2-for-parsing-and-xpath.html for more info :)

Tags: , ,

Development

blog comments powered by Disqus

Creative Commons License
This work is licensed under a Creative Commons Attribution-Share Alike 2.5 Sweden License.


Welcome to the Dropit blog!

Here we, the people that work at Dropit, will write about stuff that interests us. For example web development, especially with .NET and EPiServer - but we'll also talk about other techniques that interest us, marketing on the web, social phenomenons, pop culture, games and software development in general.