Google Analytics API - Error occurred while sending the request - Service account issue
See original GitHub issueHi , 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.
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:
- Created 3 years ago
- Comments:44
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I checked with IT team .Now They have enabled Port. Its working now. Thanks for your effort. Thank you so much.
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.