Search code examples
google-apigoogle-analytics-firebase

Get access_token from google service account for embed api


I've wanted to embed api without my user logging in to their account. I'm new to google api and I wanted to use embed api Like this one I've been searching since yesterday how to implement this either by javascript or .net.

I have this code in .net

       string keyFilePath = Server.MapPath("~/Libraries/googleKey/key.json");
        string json = System.IO.File.ReadAllText(keyFilePath);


        var cr =  JsonConvert.DeserializeObject<PersonalServiceAccountCred>(json);

        var xCred = new ServiceAccountCredential(new ServiceAccountCredential.Initializer(cr.client_email)
        {
            Scopes = new[] {
          AnalyticsReportingService.Scope.AnalyticsReadonly
    }
        }.FromPrivateKey(cr.private_key));

I'm getting a null token, i'm confused, most examples are in php or python.


Solution

  • you can use a service Account, make sure you have access granted to the service account