Re: Google Analytics API v3 - Get data with c#

3,878 views
Skip to first unread message

GRodrigues

unread,
Sep 21, 2012, 11:31:32 AM9/21/12
to google-analytics...@googlegroups.com
Olá Bruno,
 
Estou com um problema semelhante. Preciso de extrair data do GA para SQL Server 2008.
 
Conseguiste arranjar alguma solução?
 
Um abraço,
Gonçalo

Sexta-feira, 14 de Setembro de 2012 16:06:33 UTC+1, bruno ortiz escreveu:
hi everybody, i was using the code to get data from google analytics api with c#, and tried to change to new version v3, but i dont know how to get de data in this new version v3, someone can help me? i´m sorry for my poor english.

thanks for any help.

            const string USERNAME = "MYUSER"; //Usuario
            const string PASSWORD = "MYPASSWORD"; //Senha

            const string dataFeedUrl = "https://www.googleapis.com/analytics/v3/data/";
            string profileId = ga;

            AnalyticsService service = new AnalyticsService("AnalyticsSampleApp");
            service.setUserCredentials(USERNAME, PASSWORD);
            DataQuery query = new DataQuery(dataFeedUrl);
            DataQuery query2 = new DataQuery(dataFeedUrl);
         
            int mesAtual = DateTime.Today.Month;
            int anoAtual = DateTime.Now.Year;            
            int mesAnterior = (mesAtual - 1);
            int diasMes = DateTime.DaysInMonth(2012, mesAnterior);

            query.Ids = profileId;            
            query.Metrics = "ga:visits,ga:visitors,ga:pageviews"; //pegar métricas
            query.Dimensions = "ga:date"; 
            query.Sort = "ga:date"; //Ordenar

            query.GAStartDate = DateTime.Now.AddDays(-7).ToString(2012+"-0"+mesAnterior +"-01");
            query.GAEndDate = DateTime.Now.ToString(2012 + "-0" + mesAnterior + "-" + diasMes);

Mike Sullivan

unread,
Sep 21, 2012, 12:04:05 PM9/21/12
to google-analytics...@googlegroups.com
Check the docs...you can't use username/password (a.k.a. ClientLogin) with V3 API. You need to use Oauth.

John Jones

unread,
Sep 27, 2012, 9:47:27 PM9/27/12
to google-analytics...@googlegroups.com
This is my v3 code to pull reports, profile xxxxx@developer.gserviceaccount.com needs to be a User on the account and not Admin
https://groups.google.com/forum/?fromgroups=#!topic/google-analytics-data-export-api/quIN0vX-psw

Brian White

unread,
Sep 28, 2012, 9:48:43 AM9/28/12
to google-analytics...@googlegroups.com
How do you tell if a user is an administrator or not?

--
 
 

John Jones

unread,
Sep 28, 2012, 9:54:33 AM9/28/12
to google-analytics...@googlegroups.com
From the Google Analytics dashboard  -> Account List -> Click on the account and you should see the user tab -> Role make sure the service account is a user.

--
 
 

Message has been deleted
Message has been deleted

Til

unread,
Oct 4, 2012, 12:57:24 AM10/4/12
to google-analytics...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages