Maison > Questions et réponses > le corps du texte
Je veux juste comprendre comment exécuter batchRunReports en php, j'ai essayé un exemple mais il donne un message d'erreur fatale complexe. J'ai parcouru la documentation mais je n'ai rien trouvé en rapport avec mon problème. Je peux exécuter la requête de mon choix en utilisant les outils de la documentation, mais je ne peux pas la transmettre à php.
use Google\Analytics\Data\V1beta\BetaAnalyticsDataClient; use Google\Analytics\Data\V1beta\DateRange; use Google\Analytics\Data\V1beta\Dimension; use Google\Analytics\Data\V1beta\Metric; use Google\Analytics\Data\V1beta\MetricAggregation; $property = "properties/XXXXXXXXX"; $client = new BetaAnalyticsDataClient(); $client->batchRunReports([ "requests" => [ [ "property" => $property, "dataRanges" => [ new DateRange(["start_date" => "7daysAgo"], ["end_date" => "today"]), ], "dimensions" => [ new Dimension(["name" => "eventName"]), ], "metrics" => [ new Metric(["name" => "eventCount"]), ] ], [ "property" => $property, "dataRanges" => [ new DateRange(["start_date" => "7daysAgo"], ["end_date" => "today"]), ], "dimensions" => [ new Dimension(["name" => "deviceCategory"]), ], "metrics" => [ new Metric(["name" => "activeUsers"]), ] ], ] ]);
Erreur fatale : exception non détectée : attente de GoogleAnalyticsDataV1betaRunReportRequest. Dans F:xampphtdocsother2_templateapi-test-completedgoogle-analyticsvendorgoogleprotobufsrcGoogleProtobufInternalGPBUtil.php:198 Trace de pile :
#0 F:xampphtdocsother2_templateapi-test-completedgoogle-analyticsvendorgoogleprotobufsrcGoogleProtobufInternalRepeatedField.php(187) : interne ::checkMessage(Array, 'GoogleAnalytic...' )
#1 F:xampphtdocsother2_templateapi-test-completedgoogle-analyticsvendorgoogle protobufsrcGoogleProtobufInternalGPBUtil.php(210): GoogleProtobufInternalRepeatedField->offsetSet(NULL, Array)
#2 F:xampphtdocsother 2_templateapi-test-complete d google-analyticsvendorgoogleanalytics-datasrcV1betaBatchRunReportsRequest.php ( 126) : GoogleProtobufInternalGPBUtil::checkRepeatedField(Array, 11, 'GoogleAnalytic ...')
#3 F:xampphtdocsother2_templateapi-test-completedgoogle-analyticsvendorgoogleanalytics-datasrcV1betaGapicBetaAnalyticsDataGapicClient .php(421) : GoogleAnalyticsDataV1betaB atchtics RunReportsRequest->setRequests(Array)
#4 F:xampphtdocsother2_templateapi-test-completedgoogle-analytics test.php(46) : GoogleAnalyticsDataV1betaGapicBetaAnalyticsDataGapicClient->batchRunReports(Array)
#5 {main} lance F:xampphtdocsother2_templateapi-test-completedgoogle-analytics fournisseurgoogleprotobufsrc GoogleProtobufInternalGPBUtil.php ligne 198
P粉7920264672024-01-30 10:45:43
Vous devez utiliser l'objet RunReportRequest dans le tableau "requests" pour exécuter batchRunReports. N'oubliez pas d'ajouter "l'attribut" comme dans la requête batchRunReports.
$response = $client->batchRunReports([ "property" => $property, "requests" => [ new RunReportRequest( [ "property" => $property, "date_ranges" => [ new DateRange(["start_date" => "7daysAgo", "end_date" => "today"]), ], "dimensions" => [ new Dimension(["name" => "eventName"]), ], "metrics" => [ new Metric(["name" => "eventCount"]), ] ]), new RunReportRequest([ "property" => $property, "date_ranges" => [ new DateRange(["start_date" => "7daysAgo", "end_date" => "today"]), ], "dimensions" => [ new Dimension(["name" => "deviceCategory"]), ], "metrics" => [ new Metric(["name" => "activeUsers"]), ] ]), ] ]);