I'm trying to call the GA4 analytics api using the API quickstart guilde, but I'm getting a GRPC error when calling:
Grpc.Core.RpcException: 'Status(StatusCode="Unavailable", Detail="failed to connect to all addresses", DebugException="Grpc.Core.Internal.CoreErrorDetailException: {"created":"@1686669889.017000000","description":"Failed to pick subchannel","file":"......\src\core\ext\filters\client_channel\client_channel.cc","file_line":3218,"referenced_errors":[{"created":"@1686669889.017000000","description":"failed to connect to all addresses","file":"......\src\core\lib\transport\error_utils.cc","file_line":165,"grpc_status":14}]}")'
Any advice?
This is the sample code I am using:
BetaAnalyticsDataClient client = BetaAnalyticsDataClient.Create();
// Initialize request argument(s)
//RunReportRequest request = new RunReportRequest
//{
// Property = "properties/" + propertyId,
// Dimensions = { new Dimension { Name = "eventName" }, },
// //Metrics = { new Metric { Name = "eventCount" }, },
// DateRanges = { new DateRange { StartDate = "2023-03-31", EndDate = "today" }, },
//};
RunReportRequest request = new RunReportRequest
{
Property = "properties/" + propertyId,
Dimensions = { new Dimension { Name = "city" }, },
Metrics = { new Metric { Name = "activeUsers" }, },
DateRanges = { new DateRange { StartDate = "2020-03-31", EndDate = "today" }, },
};
try
{
// Make the request
var response = client.RunReport(request);
Console.WriteLine("Report result:");
foreach (Row row in response.Rows)
{
Console.WriteLine("{0}, {1}", row.DimensionValues[0].Value, row.MetricValues[0].Value);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
throw;
}```
This seems like a network issue which should be solved by using correct protocol. You can try to set GrpcAdapter property of the builder when creating the client?
var client = new BetaAnalyticsDataClientBuilder
{
GrpcAdapter = RestGrpcAdapter.Default
}.Build();
You can find more details in official docs: https://googleapis.dev/dotnet/Google.Analytics.Data.V1Beta/latest/#using-the-rest-http11-transport