.net - Route Google Analytics v3 API through a proxy server -
we using google analytics api v3 (dot net version) reporting statistical data on our website. have code running fine on local machine, wouldn't work on production server due firewall rules. our system admin suggests try , use proxy. searched on internet guidelines set proxy google analytics api service, no luck. appreciate pointers in regard.
edit:
public datatable getsearchtrends() { string googleanalyticsprofileid = appconfigmanager.getgoogleanalyticsprofileidforinis(); var service = new analyticsservice(new baseclientservice.initializer() { authenticator = authenticate() }); dataresource.garesource.getrequest request = service.data.ga.get( googleanalyticsprofileid, string.format("{0:yyyy-mm-dd}", startdate), string.format("{0:yyyy-mm-dd}", enddate), googleanalyticssearchuniquesmetric ); request.dimensions = googleanalyticssearchkeywordmetric; request.sort = string.concat("-", googleanalyticssearchuniquesmetric); request.maxresults = numberofsearchtrendstofetch; gadata response = request.fetch(); return searchtrendshelper.converttodatatable( response.rows, searchtrendskeywordsexcludelist, numberofsearchtrendstodisplay ); } private iauthenticator authenticate() { string googleanalyticsservicescope = analyticsservice.scopes.analyticsreadonly.getstringvalue(); string googleapiserviceaccountid = appconfigmanager.getgoogleapiserviceaccountid(); string googleapiserviceaccountkeyfile = appconfigmanager.getgoogleapiserviceaccountkeyfile(); string googleapiserviceaccountkeypassword = appconfigmanager.getgoogleapiserviceaccountkeypassword(); authorizationserverdescription desc = googleauthenticationserver.description; x509certificate2 key = new x509certificate2( httpcontextfactory.current.server.mappath(googleapiserviceaccountkeyfile), googleapiserviceaccountkeypassword, x509keystorageflags.exportable | x509keystorageflags.machinekeyset ); assertionflowclient client = new assertionflowclient(desc, key) { serviceaccountid = googleapiserviceaccountid, scope = googleanalyticsservicescope, }; oauth2authenticator<assertionflowclient> auth = new oauth2authenticator<assertionflowclient>( client, assertionflowclient.getstate ); return auth; }
i did not find useful documentation in forums or on internet, decided use system.net configuration on web.config.
<system.net> <defaultproxy usedefaultcredentials="true"> <proxy proxyaddress="http://abc.com:3128" usesystemdefault="true" bypassonlocal="true"/> <bypasslist> <add address="http://xyz.com" /> <add address="http://www.example.com" /> </bypasslist> </defaultproxy> </system.net> any requests don't want pass through proxy, can added <bypasslist>. has added advantage that, whenever google api class library changes, don't have bother re-writing code set proxy. :-)
Comments
Post a Comment