Analytics API 2

<?php

function getPageView()
{
	require_once 'vendor/autolod.php';

	$viewId = '';
	$client_email = '';
	$private_key = file_get_contents("");

	$metrics = "ga:pageviews";

	$from = '2018-01-30';
	$to = '2018-01-31';

	$option = &#91;
		"dimensions" => 'ga:date',
		"max-results" => 10000,
		"sort" => "ga:date",
	];

	$scope = ["https://www.googleapis.com/auth/analytics.readonly"];

	$credentials = new Google_Auth_AssertionCredentials($client_email, $scopes, $private_key);

	$client = new Google_Client();
	$client->setAssertionCredentials($credentials);

	if ($client->getAuth()->isAccessTokenExpired()){
		$client->getAuth()->refreshTokenWithAssertion($credentials);
	}
	$_SESSION["service_token"] = $client->getAccessToken();

	$analytics = new Google_Service_Analytics($client);

	$obj = $analytics->data_ga->get(
		"ga:{$viewId}",
		$from,
		$to,
		$metrics,
		$option
	);

	echo '<pre>';
	var_dump($obj->rows);
	echo '</pre>';
}