我正在使用通过 composer v2.0 安装的 google-api-php-client。我需要每天/每周/每月等提取数据。但是,我只得到总数。
我可能遗漏了一处房产,但我在任何地方都找不到它应该是什么。
这是我正在使用的请求
$client = new Google_Client();
$client->setClientId(GOOGLE_CLIENT_ID);
$client->setClientSecret(GOOGLE_CLIENT_SECRET);
$client->setRedirectUri(GOOGLE_REDIRECT_URL);
$client->setAccessType('online'); // default: offline
$client->setApplicationName('Login to my app');
$client->addScope(Google_Service_Analytics::ANALYTICS_READONLY);
$analytics = new Google_Service_AnalyticsReporting($client);
function getReport($analytics, $profileId) {
$VIEW_ID = $profileId;
// Create the DateRange object.
$dateRange = new Google_Service_AnalyticsReporting_DateRange();
$dateRange->setStartDate("7daysAgo");
$dateRange->setEndDate("today");
$dateRange2 = new Google_Service_AnalyticsReporting_DateRange();
$dateRange2->setStartDate("14daysAgo");
$dateRange2->setEndDate("7daysAgo");
// Create the Metrics object.
$sessions = new Google_Service_AnalyticsReporting_Metric();
$sessions->setExpression("ga:sessions");
$sessions->setAlias("Sessions");
$new_users = new Google_Service_AnalyticsReporting_Metric();
$new_users->setExpression("ga:newUsers");
$new_users->setAlias("New users");
$organic = new Google_Service_AnalyticsReporting_Metric();
$organic->setExpression("ga:organicSearches");
$organic->setAlias("Organic results");
// Create the ReportRequest object.
$request = new Google_Service_AnalyticsReporting_ReportRequest();
$request->setViewId($VIEW_ID);
$request->setDateRanges(array($dateRange,$dateRange2));
$request->setMetrics(array($sessions, $new_users, $organic));
$body = new Google_Service_AnalyticsReporting_GetReportsRequest();
$body->setReportRequests( array( $request) );
return $analytics->reports->batchGet( $body );
}
这仅返回我指定的日期范围的总数。
我希望你能帮我找到丢失的财产或我做错了什么。谢谢你。
桃花长相依