国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Google Analytics Data API v1:執(zhí)行 runReport 並僅檢索 JSON 數(shù)據(jù)
P粉356361722
P粉356361722 2023-12-13 17:37:47
0
1
536

目前我正在嘗試使用 Google Analytics Data API v1 從 GA4 取得 json 資料。但是,返回的回應(yīng)不是純 json 數(shù)據(jù),相反,如果我只是使用 PHP 列印它,它會(huì)給我 {}。但是,使用預(yù)定義的方法,我們可以獲得該值。請(qǐng)問(wèn),有沒(méi)有辦法得到純json數(shù)據(jù)?

<?php
putenv('GOOGLE_APPLICATION_CREDENTIALS=xxx.json');

require_once 'vendorautoload.php';

use GoogleAnalyticsDataV1betaBetaAnalyticsDataClient;
use GoogleAnalyticsDataV1betaDateRange;
use GoogleAnalyticsDataV1betaDimension;
use GoogleAnalyticsDataV1betaMetric;
use GoogleCloudBigQueryConnectionRest;

$property_id = 'xxx'; // GA4 property ID

// Using a default constructor instructs the client to use the credentials
// specified in GOOGLE_APPLICATION_CREDENTIALS environment variable.
$client = new BetaAnalyticsDataClient();

// Make an API call.
$response = $client->runReport([
  'property' => 'properties/' . $property_id,
  'dateRanges' => [
    new DateRange([
      'start_date' => '2022-06-30',
      'end_date' => 'today',
    ]),
  ],
  'dimensions' => [
    new Dimension(
      [
        'name' => 'city',
      ]
    ),
  ],
  'metrics' => [
    new Metric(
      [
        'name' => 'activeUsers',
      ]
    )
  ]
]);

print 'Report result: ' . PHP_EOL;

printVisitorsLocationInNumber($response);

function printVisitorsLocationInNumber($resp) {
  foreach ($resp->getRows() as $row) {
    echo
    $row->getDimensionValues()[0]->getValue() . ' ' . $row->getMetricValues()[0]->getValue() . PHP_EOL . '</br>';;
  }
}


#
P粉356361722
P粉356361722

全部回覆(1)
P粉726133917
echo $response->serializeToJsonString(); // Prints JSON string

$response\Google\Analytics\Data\V1beta\RunReportResponse 的實(shí)例,它擴(kuò)充自 \Google\Protobuf\Internal\Message。因此,您可以使用相同的 serializeToJsonString() 方法。

最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板