Comments (2)
I upgraded rto v0.3 and I still get same error.
Error calling POST https://analyticsreporting.googleapis.com/v4/reports:batchGet: (400) Invalid JSON payload received. Unknown name "comparison_value" at 'report_requests[0].metric_filter_clauses': Cannot find field.
Invalid JSON payload received. Unknown name "metric_name" at 'report_requests[0].metric_filter_clauses': Cannot find field.
Invalid value at 'report_requests[0].metric_filter_clauses.operator' (TYPE_ENUM), "GREATER_THAN"
My code:
$metricFilterSessions = new \Google_Service_AnalyticsReporting_MetricFilter();
$metricFilterSessions->setMetricName("ga:sessions");
$metricFilterSessions->setOperator("GREATER_THAN");
$metricFilterSessions->setComparisonValue("399");
...
$request = new \Google_Service_AnalyticsReporting_ReportRequest();
...
$request->setMetricFilterClauses($metricFilterSessions);
from google-api-php-client-services.
The issue is not with this library. If you look at the raw HTTP request you're making, it accurately reflects the expected JSON values:
{
"reportRequests": [{
"metricFilterClauses": {
"comparisonValue": "399",
"metricName": "ga:sessions",
"operator": "GREATER_THAN"
}
}]
}
However, if you use the Analytics Reporting API Explorer, you'll see the structure should actually look like this:
{
"reportRequests": [{
"viewId": 1,
"metricFilterClauses": [{
"filters": [{
"comparisonValue": "399",
"metricName": "ga:sessions",
"operator": "GREATER_THAN"
}]
}]
}]
}
The difference here is the filter
clause, the viewId
, and some nested arrays. This is an issue with the library, that we are not type-checking these. I'll look into fixing that. However, the error you're seeing using the snake-cased variables are coming from the Analytics API, so the formatting difference is in the error, and not the request.
Try something like this instead:
// create the client
$client = new Google_Client();
$client->setAuthConfig($credentialsFile);
$client->setApplicationName("Client_Library_Examples");
$client->setScopes([Google_Service_AnalyticsReporting::ANALYTICS]);
// create the metric filter
$metricFilterSessions = new Google_Service_AnalyticsReporting_MetricFilter();
$metricFilterSessions->setMetricName("ga:sessions");
$metricFilterSessions->setOperator("GREATER_THAN");
$metricFilterSessions->setComparisonValue("399");
$metricFilterClause = new Google_Service_AnalyticsReporting_MetricFilterClause();
$metricFilterClause->setFilters([$metricFilterSessions]);
// create the report requests
$reportRequest = new Google_Service_AnalyticsReporting_ReportRequest();
$reportRequest->setMetricFilterClauses([$metricFilterClause]);
$reportRequest->setViewId($yourViewId); // you have to set your own View ID here!!
$getReportsRequest = new Google_Service_AnalyticsReporting_GetReportsRequest();
$getReportsRequest->setReportRequests([$reportRequest]);
// make the call
$service = new Google_Service_AnalyticsReporting($client);
$results = $service->reports->batchGet($getReportsRequest);
I hope this helps!
from google-api-php-client-services.
Related Issues (20)
- \Google\Service\Calendar\Event::getDescription() returns NULL instead of "" HOT 3
- chore: update copyright year
- Slow download time impacting our tests. HOT 2
- HangoutsChat - Cannot add user into a space HOT 2
- composer install fails while trying to download "google/apiclient-services" everytime for the last three weeks (duplicate by mistake)
- composer install fails while trying to download "google/apiclient-services" everytime for the last three weeks HOT 6
- Obtain Domains list HOT 1
- Package is difficult to install HOT 1
- User does not have sufficient permissions for this profile. HOT 2
- Send push notification to multiple device in single request HOT 3
- `ValueRange:getValues()` returns null for empty sheet. HOT 3
- Dynamic property declarations in PHP 8.2 HOT 1
- Method: verificationTokens.generate missing in MyBusinessVerifications HOT 4
- Dynamic property declarations in PHP 8.2 (follow-up) HOT 4
- getResources() now returns null
- Add `@throws \Google\Service\Exception` in method's phpdoc HOT 2
- Safe browsing client refers to non existent v5 version HOT 5
- TransitType enum not generated HOT 4
- Hey, I’ve been working with Swoole and I think there’s an issue when the application runs in a resident memory environment
- Add a script to generate the golden clients from the golden files
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from google-api-php-client-services.