How to use Google.Apis.Analytics.v3 API with vb.net service app -


i have managed autenticate self succesfully google etc. need how use google.apis.analytics.v3 or google.apis.analytics.v3.data dll retrive data. example need last month vistors. far have this:

imports system.security.cryptography.x509certificates imports system.threading imports google.apis.auth.oauth2 imports mailbee imports mailbee.imapmail imports mailbee.smtpmail imports system.data imports system.io imports system.data.sqlclient imports google.apis.analytics.v3 imports google.apis.analytics.v3.data imports google.apis.authentication.oauth2.dotnetopenauth imports google.apis.services imports google.apis.util   public class gaimport      inherits system.web.ui.page      public shared sub main(sender object, e eventargs)         dim serviceaccountemail string = "xxxxxxxxxxxxxxxxxxx@developer.gserviceaccount.com"         dim useremail string = "xxxxx@gmail.com"          dim certificate new x509certificate2("c:\works\gaimport\gaimport\analyticsdata-xxxxxxxxxxxx.p12", _             "notasecret", x509keystorageflags.exportable)          dim credential new serviceaccountcredential( _             new serviceaccountcredential.initializer(serviceaccountemail) { _             .scopes = new string() {"https://www.googleapis.com/auth/analytics.readonly"} _         }.fromcertificate(certificate))          if credential.requestaccesstokenasync(cancellationtoken.none).result             dim xoauthkey string = oauth2.getxoauthkeystatic(useremail, credential.token.accesstoken)                console.writeline("test" & xoauthkey)           end if      end sub        end class 

now need somehing analytics part working. how use dll? can reguest feed google (like didi clientid logins)?

i found traight forfard solution case (after getting acces token):

dim webclient new system.net.webclient webclient.encoding = system.text.encoding.utf8 dim requesturl = "https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3a" & domainidid(domainrno) & "&start-date=" & viimekuunalkuset & "&end-date=" & viimekuunloppuset & "&metrics=ga%3ausers%2cga%3asessions%2cga%3apageviews&access_token=" & credential.token.accesstoken  dim resultb string = webclient.downloadstring(requesturl) 

then handeled json wanted get:

dim myj = jobject.parse(resultb)                 dim totalsforallresults = convert.toint32(myj("totalsforallresults")("ga:sessions"))                 dim totalsforallresultsusers = convert.toint32(myj("totalsforallresults")("ga:users"))                 dim totalsforallresultspgw = convert.toint32(myj("totalsforallresults")("ga:pageviews")) 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -