c# - Google Analytics throws 403 error -


i attempting download metric data google analytics using c# , performing user authentication oauth 2.0. i'm using installed application authorisation flow, requires logging google , copy-and-pasting code application. i'm following code taken google-api-dotnet-client:

private void downloaddata() {     service = new analyticsservice(new baseclientservice.initializer() {         authenticator = createauthenticator(),     });     var request = service.data.ga.get(accountid, startdate, enddate, metrics);     request.dimensions = dimensions;     request.startindex = 1;     request.maxresults = 10000;     var response = request.execute(); // throws google.googleapiexception }  private iauthenticator createauthenticator() {     var provider = new nativeapplicationclient(googleauthenticationserver.description) {         clientidentifier = "123456789012.apps.googleusercontent.com",         clientsecret = "xxxxxxxxxxxxxxxxxxxxxxxx",     };     return new oauth2authenticator<nativeapplicationclient>(provider, login); }  private static iauthorizationstate login(nativeapplicationclient arg) {     // generate authorization url.     iauthorizationstate state = new authorizationstate(new[] { analyticsservice.scopes.analyticsreadonly.getstringvalue() });     state.callback = new uri(nativeapplicationclient.outofbandcallbackurl);     uri authuri = arg.requestuserauthorization(state);      // request authorization user opening browser window.     process.start(authuri.tostring());     console.write("google authorization code: ");     string authcode = console.readline();      // retrieve access token using authorization code.     state = arg.processuserauthorization(authcode, state);     return state; } 

the google account xxxxxx@gmail.com registered client id , secret. same account has full administration rights in google analytics. when try pull data google analytics, goes through authorisation process, appears work properly. fails with:

google.googleapiexception
google.apis.requests.requesterror
user not have sufficient permissions profile. [403]
errors [
message[user not have sufficient permissions profile.] location[ - ] reason [insufficientpermissions] domain[global]
]

i've been struggling few hours. i've double checked correct user being used, , authorised on google analytics. i'm @ loss misconfigured. ideas requires configuring or changing?

if auth seems working working suggestion make sure you're providing correct id because based on code snippet:

var request = service.data.ga.get(accountid, startdate, enddate, metrics); 

one can assume you're using account id. if so, incorrect , you'd receive error you've encountered. need query profile id.

if login google analytics using web interface you'll see following pattern in url of browser's address bar:

/a12345w654321p9876543/ 

the number following p profile id, 9876543 in example above. make sure you're using , should using table id ga:9876543.

if isn't id issue instead query management api list accounts , see have access , verify auth working correctly.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -