c# - Why do I keep getting 403 User does not have sufficient permission for this profile error from Analytics API -


edit: have read following posts on stack overflow, don't think have solution looking for:

google analytics throws 403 error google analytics api: "user not have sufficient permissions account."

i creating installed application in c# access , display google analytics data.

i have read google's documentation oauth v2.0 , analytics v3 api, , cannot retrieve analytics data. here have done far.

  1. navigate following url in web browser prompted log in google account (the account owns analytics account , has full ownership , permission) or if browser has saved login, accept screen comes asking me confirm want allow app access analytics data. here url: https://accounts.google.com/o/oauth2/auth?redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code&client_id=xxxxxx.apps.googleusercontent.com&scope=https%3a%2f%2fwww.googleapis.com%2fauth%2fanalytics.readonly&approval_prompt=force&access_type=offline");

  2. after code returned , retrieved browser title window oauth 2.0 documentation specifies installed applications, take code , create following request returns access token:

        webrequest request = webrequest.create("https://accounts.google.com/o/oauth2/token");     string body = string.format("code={0}&client_id=xxxxxxxxxxx.apps.googleusercontent.com&client_secret=xxxxxxxxxxx&redirect_uri=urn:ietf:wg:oauth:2.0:oob&grant_type=authorization_code"         ,browser.oauthcode);     request.method = "post";     byte[] reqbytes = encoding.utf8.getbytes(body);     request.contenttype = "application/x-www-form-urlencoded";     request.contentlength = reqbytes.length;     request.getrequeststream();     stream stream = request.getrequeststream();     stream.write(reqbytes, 0, (int)request.contentlength);      webresponse response = request.getresponse();     stream s = response.getresponsestream();     streamreader sr = new streamreader(s);      string json = sr.readtoend();      oauthresponse tokenholder = new oauthresponse();     tokenholder = newtonsoft.json.jsonconvert.deserializeobject<oauthresponse>(json);      return tokenholder.accesstoken; 
  3. finally, after retrieving access token, create request retrieve analytics data so:

    public webrequest apirequest() {     string oauthtoken = oauthtoken();       //need change people can select different ones     string idparam = "ids=ga:xxxxxx";      startdate = "start-date=" + startdate;     enddate = "end-date=" + enddate;      string totaleventsmetric = "ga:totalevents";     string uniqueeventsmetric = "ga:uniqueevents";      string categorydimension = "ga:eventcategory";     string actiondimension = "ga:eventaction";     string labeldimension = "ga:eventlabel";      string parameters = "";      if ((bool)this._showtotalevents.ischecked)         parameters += "metrics=" + totaleventsmetric;     if ((bool)this._shwouniqueevents.ischecked)         if (parameters != "")             parameters += "," + uniqueeventsmetric;         else             parameters += "metrics=" + uniqueeventsmetric;     if ((bool)this._showcategory.ischecked)         if (parameters != "")             parameters += "&dimensions=" + categorydimension;         else             parameters += "dimensions=" + categorydimension;     if ((bool)this._showaction.ischecked)         if (parameters != "" & parameters.contains("dimensions"))             parameters += "," + actiondimension;         else if (parameters != "" & !parameters.contains("dimensions"))             parameters += "&dimensions=" + actiondimension;         else             parameters += "dimensions=" + actiondimension;     if ((bool)this._showlabel.ischecked)         if (parameters != "" & parameters.contains("dimensions"))             parameters += "," + labeldimension;         else if (parameters != "" & !parameters.contains("dimensions"))             parameters += "&dimensions=" + labeldimension;         else             parameters += "dimensions=" + labeldimension;      if (parameters != "")     {         parameters += "&" + idparam;         parameters += "&" + startdate;         parameters += "&" + enddate;     }     else     {         parameters += idparam;         parameters += "&" + startdate;         parameters += "&" + enddate;         parameters += "&metrics=" + totaleventsmetric;         parameters += "," + uniqueeventsmetric;     }      string url = string.format("https://www.googleapis.com/analytics/v3/data/ga?{0}", parameters);     webrequest request = webrequest.create(url);     request.method = "get";     request.headers.add("authorization: bearer " + oauthtoken);     return request; } 

my url ends looking this:

https://www.googleapis.com/analytics/v3/data/ga?metrics=ga:totalevents,ga:uniqueevents&dimensions=ga:eventcategory,ga:eventaction,ga:eventlabel&ids=ga:xxxxx&start-date=2013-12-01&end-date=2014-01-01

and header:

{authorization: bearer oauthtokengoeshere}

and error every time:

{"error":{"errors":[{"domain":"global","reason":"insufficientpermissions","message":"user not have sufficient permissions profile."}],"code":403,"message":"user not have sufficient permissions profile."}}

i cannot figure out why getting error when installed program. log actual account in web browser opens before click accept , retrieve oauth code exchange token. have tried adding app engine , compute engine email address form developer's console analytics account using web interface, not help. there no email address associated client ids installed applications either, presumably because have log in in browser before can code.

i tried passing token in parameter instead of header, did not work either.

i not sure here.

i providing wrong id number access analytics data. using id contained in table id (i pretty sure called) looks ua-xxxxxx-1 when account id number. after going , rereading of documentation saw said use profile (view) id.

actually post: google analytics throws 403 error

mentioned need make sure using correct id, reason did not think referred me because called number profile id, when looking in google analytics, not find profile id. in analytics web interface, called view id. must have gotten lost in sea of documentation , forgot part:

https://developers.google.com/analytics/devguides/reporting/core/v3/reference#ids

where says use "view (profile) id".


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -