Rumah > Soal Jawab > teks badan
Saya hanya mahu memahami cara menjalankan batchRunReports dalam php, saya mencuba contoh tetapi ia memberikan mesej ralat maut yang kompleks. Saya telah melihat melalui dokumentasi tetapi tidak dapat mencari apa-apa yang berkaitan dengan masalah saya. Saya boleh menjalankan pertanyaan yang saya mahu menggunakan alat dalam dokumentasi, tetapi saya tidak boleh menghantarnya ke 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"]), ] ], ] ]);
-testgoogle-templates #5:xamppht svendorgoogleprotobufsrc GoogleProtobufInternalGPBUtil.php baris 198 🎜🎜Ralat maut: Pengecualian tidak ditangkap: Menjangkakan GoogleAnalyticsDataV1betaRunReportRequest. Dalam F:xampphtdocsother2_templateapi-test-completedgoogle-analyticsvendorgoogleprotobufsrcGoogleProtobufInternalGPBUtil.php:198 Surih tindanan:
#0 F:xampphtdocsother2_templateapi-test-completedgoogle-analyticsvendorgoogleReprotobufsvendorgoogle til::checkMessage(Array, 'GoogleAnalytic...' )
#1 F:xampphtdocsother2_templateapi-test-completedgoogle-analyticsvendorgoogle protobufsrcGoogleProtobufInternalGPBUtil.php(210): GoogleProtobufInternalRepeatedField->offsetSet(NULL, Array)
2doc-templatex google-analyticsvendorgoogleanalytics-datasrcV1betaBatchRunReportsRequest.php ( 126): GoogleProtobufInternalGPBUtil::checkRepeatedField(Array, 11, 'GoogleAnalytic ...') #3 F:xampphtdocsother2_templateapi-test-completedgoogle-analyticsvendorgoogleanalytics-datasrcV1betaGapicDatalytics12.phpBetalytics1.php Batchtics RunReportsRequest->setRequests(Array) #4 F:xampphtdocsother2_templateapi-test-completedgoogle-analytics test.php(46): GoogleAnalyticsDataV1betaGapicBetaAnalyticsDataGapicClient->batchRunReports(Array)
P粉7920264672024-01-30 10:45:43
Anda perlu menggunakan objek RunReportRequest dalam tatasusunan "permintaan" untuk menjalankan batchRunReports. Jangan lupa untuk menambah "atribut" seperti dalam permintaan 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"]), ] ]), ] ]);