question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Google Analytics API - Error occurred while sending the request - Service account issue

See original GitHub issue

Hi , I am using service account to get the data from Google analytics. And its working fine in local. But not working after deployment in IIS. Getting error an error occurred while sending the request.

1

image

Please find my code below:

try
{

    var service = new AnalyticsService();
    string[] scopes = new string[] { AnalyticsService.Scope.Analytics };              // view and manage your Google Analytics data
    var keyFilePath = Server.MapPath(Url.Content("~/Content/CertificateKey/key.p12"));
    var serviceAccountEmail = "******@******.iam.gserviceaccount.com";

    //loading the Key file
    var certificate = new X509Certificate2(keyFilePath, "notasecret", X509KeyStorageFlags.MachineKeySet
        | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable);

    var credential = new ServiceAccountCredential(new ServiceAccountCredential.Initializer(serviceAccountEmail)
    {
        Scopes = scopes
    }.FromCertificate(certificate));


    service = new AnalyticsService(new BaseClientService.Initializer()
    {
        HttpClientInitializer = credential,
        ApplicationName = "my Website",

    });


    DataResource.GaResource.GetRequest request = service.Data.Ga.Get("ga:18261****", fromDate, toDate, "ga:users");
    request.MaxResults = 1000;
    GaData result = request.Execute();
    ViewBag.GAUsers = result.Rows[0].First().ToString();

}

catch (Exception ex)
{
    ViewBag.errorMsg = ex.Message.ToString();
}

and in errorMsg i got the message “An error occurred while sending the request”.

Someone kindly look into this issue and provide me the solution please. Thank you .

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:44

github_iconTop GitHub Comments

1reaction
Sathyashetty99commented, Jun 11, 2020

I checked with IT team .Now They have enabled Port. Its working now. Thanks for your effort. Thank you so much.

0reactions
jskeetcommented, Jun 11, 2020

You ask your IT administrator. Please bear in mind we have basically no information about the infrastructure you’re using - whereas you’re right there, with the team that runs that infrastructure, etc.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error Responses | Analytics Core Reporting API
Indicates that the 10 concurrent requests per view (profile) in the Core Reporting API has been reached. Retry using exponential back-off.
Read more >
Analytics Google API Error 403: "User does not have any ...
This message has no sense: my account has google analytics data, tracking multiple websites, and I can access it from web browser without ......
Read more >
Google Analytics Errors - Tag Assistant Help
This error denotes that the call to google-analytics.com was not made and the request is missing from the JavaScript. Omitting the call to...
Read more >
Strange problem GA Api V3 with Service account auth
The error "403, User does not have any Google Analytics account" indicates the user that you are trying to access data for is...
Read more >
Google Analytics API Error
My connection to Google Analytics has been failing for the past 24 hours. Something went wrong. There was an error when processing the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found