My goal is to retrieve user's custom reports which was created in Google Analytics UI from Google Analytics API. I have registered application in Cloud console where received certificate file and generated developer email. Also configured access (granted all rights) for generated email on admin page in GA UI. To achieve my goal I am trying get segments from service, but I am not sure it is correct way to get custom reports. As a result getting only 13 default segments (with negative Ids), it is less than I can receive in Google APIs Explorer, for example one of it
{ "id": "9MaL7mLnQbWO3k52Ipni5A", "kind": "analytics#segment",
"selfLink": "https://www.googleapis.com/analytics/v3/management/segments/gaid::9MaL7mLnQbWO3k52Ipni5A", "segmentId": "gaid::9MaL7mLnQbWO3k52Ipni5A", "name": "Blog Comment Submitters", "definition": "ga:eventAction=@commentform" }
My question is it correct way to get custom reports? If it is, why I am getting only default segments?
Code:
private readonly string scope = AnalyticsService.Scopes.Analytics.GetStringValue();
private const string clientId = "xxx-xxx@developer.gserviceaccount.com";
private const string keyFile = @"C:\xxx-privatekey.p12";
string keyPassword = "notasecret";
var desc = GoogleAuthenticationServer.Description;
var key = new X509Certificate2(keyFile, keyPassword, X509KeyStorageFlags.Exportable);
var client = new AssertionFlowClient(desc, key){
ServiceAccountId = clientId,
Scope = scope
};
var auth = new OAuth2Authenticator<AssertionFlowClient>(client, AssertionFlowClient.GetState);
var gas = new AnalyticsService(new BaseClientService.Initializer { Authenticator = auth, });
var request = gas.Management.Segments.List();
var d = request.Execute();