161 lines
7.5 KiB
PHP
161 lines
7.5 KiB
PHP
<?php
|
|
|
|
namespace app\admin\controller;
|
|
use think\facade\View;
|
|
use think\facade\Lang;
|
|
/**
|
|
* ============================================================================
|
|
* 联课教育商城系统
|
|
* ============================================================================
|
|
* 版权所有 2022 刻羽互动科技有限公司,并保留所有权利。
|
|
* 网站地址: http://www.o1h.cn
|
|
* ----------------------------------------------------------------------------
|
|
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
|
|
* 不允许对程序代码以任何形式任何目的的再发布。
|
|
* ============================================================================
|
|
* 控制器
|
|
*/
|
|
|
|
|
|
use Google_Client;
|
|
use Google_Service_AnalyticsReporting;
|
|
use Google_Service_AnalyticsReporting_DateRange;
|
|
use Google_Service_AnalyticsReporting_Metric;
|
|
use Google_Service_AnalyticsReporting_ReportRequest;
|
|
use Google_Service_AnalyticsReporting_GetReportsRequest;
|
|
use Monolog\ResettableInterface;
|
|
|
|
require_once root_path() . 'vendor/autoload.php';
|
|
require_once root_path() . 'vendor/google/apiclient/src/Client.php';
|
|
require_once root_path() . 'vendor/google/apiclient/src/Service.php';
|
|
require_once root_path() . 'vendor/google/apiclient/src/Exception.php';
|
|
require_once root_path() . 'vendor/google/apiclient/src/Model.php';
|
|
require_once root_path() . 'vendor/google/apiclient/src/Collection.php';
|
|
|
|
|
|
require_once root_path() . 'vendor/google/apiclient/src/AccessToken/Revoke.php';
|
|
require_once root_path() . 'vendor/google/apiclient/src/AccessToken/Verify.php';
|
|
require_once root_path() . 'vendor/google/apiclient/src/Utils/UriTemplate.php';
|
|
require_once root_path() . 'vendor/google/apiclient/src/AuthHandler/AuthHandlerFactory.php';
|
|
require_once root_path() . 'vendor/google/apiclient/src/AuthHandler/Guzzle5AuthHandler.php';
|
|
require_once root_path() . 'vendor/google/apiclient/src/AuthHandler/Guzzle6AuthHandler.php';
|
|
require_once root_path() . 'vendor/google/apiclient/src/AuthHandler/Guzzle7AuthHandler.php';
|
|
|
|
require_once root_path() . 'vendor/google/apiclient/src/Http/Batch.php';
|
|
require_once root_path() . 'vendor/google/apiclient/src/Http/MediaFileUpload.php';
|
|
require_once root_path() . 'vendor/google/apiclient/src/Http/REST.php';
|
|
|
|
require_once root_path() . 'vendor/google/apiclient/src/Task/Retryable.php';
|
|
require_once root_path() . 'vendor/google/apiclient/src/Task/Exception.php';
|
|
require_once root_path() . 'vendor/google/apiclient/src/Task/Runner.php';
|
|
require_once root_path() . 'vendor/google/apiclient/src/Task/Composer.php';
|
|
|
|
require_once root_path() . 'vendor/google/apiclient/src/Service/Exception.php';
|
|
require_once root_path() . 'vendor/google/apiclient/src/Service/Resource.php';
|
|
|
|
require_once root_path() . 'vendor/google/apiclient/src/aliases.php';
|
|
|
|
require_once root_path() . 'vendor/google/apiclient-services/src/AnalyticsReporting/DateRange.php';
|
|
require_once root_path() . 'vendor/google/apiclient-services/src/AnalyticsReporting/Metric.php';
|
|
require_once root_path() . 'vendor/google/apiclient-services/src/AnalyticsReporting/ReportRequest.php';
|
|
require_once root_path() . 'vendor/google/apiclient-services/src/AnalyticsReporting/GetReportsRequest.php';
|
|
|
|
require_once root_path() . 'vendor/google/apiclient-services/src/AnalyticsReporting/Resource/Reports.php';
|
|
require_once root_path() . 'vendor/google/apiclient-services/src/AnalyticsReporting/Resource/UserActivity.php';
|
|
require_once root_path() . 'vendor/google/apiclient-services/src/AnalyticsReporting.php';
|
|
|
|
|
|
require_once root_path() . 'vendor/monolog/monolog/src/Monolog/ResettableInterface.php';
|
|
require_once root_path() . 'vendor/monolog/monolog/src/Monolog/Handler/HandlerInterface.php';
|
|
require_once root_path() . 'vendor/monolog/monolog/src/Monolog/Handler/AbstractHandler.php';
|
|
require_once root_path() . 'vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php';
|
|
require_once root_path() . 'vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php';
|
|
require_once root_path() . 'vendor/monolog/monolog/src/Monolog/Logger.php';
|
|
require_once root_path() . 'vendor/monolog/monolog/src/Monolog/Utils.php';
|
|
|
|
require_once root_path() . 'vendor/google/auth/src/HttpHandler/HttpHandlerFactory.php';
|
|
require_once root_path() . 'vendor/google/auth/src/HttpHandler/Guzzle6HttpHandler.php';
|
|
require_once root_path() . 'vendor/google/auth/src/Middleware/AuthTokenMiddleware.php';
|
|
require_once root_path() . 'vendor/google/auth/src/Cache/Item.php';
|
|
require_once root_path() . 'vendor/google/auth/src/UpdateMetadataInterface.php';
|
|
require_once root_path() . 'vendor/google/auth/src/ProjectIdProviderInterface.php';
|
|
require_once root_path() . 'vendor/google/auth/src/FetchAuthTokenInterface.php';
|
|
require_once root_path() . 'vendor/google/auth/src/SignBlobInterface.php';
|
|
require_once root_path() . 'vendor/google/auth/src/GetQuotaProjectInterface.php';
|
|
require_once root_path() . 'vendor/google/auth/src/CacheTrait.php';
|
|
require_once root_path() . 'vendor/google/auth/src/FetchAuthTokenCache.php';
|
|
require_once root_path() . 'vendor/google/auth/src/OAuth2.php';
|
|
require_once root_path() . 'vendor/google/auth/src/GetQuotaProjectInterface.php';
|
|
require_once root_path() . 'vendor/google/auth/src/ServiceAccountSignerTrait.php';
|
|
require_once root_path() . 'vendor/google/auth/src/CredentialsLoader.php';
|
|
require_once root_path() . 'vendor/google/auth/src/Credentials/ServiceAccountCredentials.php';
|
|
|
|
|
|
require_once root_path() . 'vendor/google/auth/src/Cache/MemoryCacheItemPool.php';
|
|
|
|
require_once root_path() . 'vendor/firebase/src/JWT.php';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Google extends AdminControl {
|
|
|
|
|
|
public function initialize() {
|
|
parent::initialize();
|
|
$KEY_FILE_LOCATION = root_path() . '/public/statapi-6dfa780d9c79.json';
|
|
|
|
// Create and configure a new client object.
|
|
$client = new Google_Client();
|
|
|
|
$client->setApplicationName("Hello Analytics Reporting");
|
|
$client->setAuthConfig($KEY_FILE_LOCATION);
|
|
$client->setScopes(['https://www.googleapis.com/auth/analytics.readonly']);
|
|
$analytics = new Google_Service_AnalyticsReporting($client);
|
|
$response = $this->getReport($analytics);
|
|
var_dump($response);
|
|
}
|
|
|
|
|
|
/**
|
|
* Queries the Analytics Reporting API V4.
|
|
*
|
|
* @param service An authorized Analytics Reporting API V4 service object.
|
|
* @return The Analytics Reporting API V4 response.
|
|
*/
|
|
public function getReport($analytics) {
|
|
|
|
// Replace with your view ID, for example XXXX.
|
|
$VIEW_ID = "<REPLACE_WITH_VIEW_ID>";
|
|
|
|
// Create the DateRange object.
|
|
$dateRange = new Google_Service_AnalyticsReporting_DateRange();
|
|
$dateRange->setStartDate("7daysAgo");
|
|
$dateRange->setEndDate("today");
|
|
|
|
// Create the Metrics object.
|
|
$sessions = new Google_Service_AnalyticsReporting_Metric();
|
|
$sessions->setExpression("ga:sessions");
|
|
$sessions->setAlias("sessions");
|
|
|
|
// Create the ReportRequest object.
|
|
$request = new Google_Service_AnalyticsReporting_ReportRequest();
|
|
$request->setViewId($VIEW_ID);
|
|
$request->setDateRanges($dateRange);
|
|
$request->setMetrics(array($sessions));
|
|
|
|
$body = new Google_Service_AnalyticsReporting_GetReportsRequest();
|
|
$body->setReportRequests( array( $request) );
|
|
return $analytics->reports->batchGet( $body );
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
} |