Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将google analytics api添加到codeigniter网站获得空白页面_Php_Codeigniter_Google Analytics - Fatal编程技术网

Php 将google analytics api添加到codeigniter网站获得空白页面

Php 将google analytics api添加到codeigniter网站获得空白页面,php,codeigniter,google-analytics,Php,Codeigniter,Google Analytics,我遵循了本教程,在我的网站上实现了谷歌分析,以查看网站浏览流量,但得到了一个空白页面 我已经下载了google API代码并添加到我的应用程序/第三方文件夹中。 创建密钥下载并上传到我的谷歌文件夹 控制器: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); require_once(BASEPATH 'application/third_party/Google/Clien

我遵循了本教程,在我的网站上实现了谷歌分析,以查看网站浏览流量,但得到了一个空白页面

我已经下载了google API代码并添加到我的应用程序/第三方文件夹中。 创建密钥下载并上传到我的谷歌文件夹

控制器:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
        require_once(BASEPATH 'application/third_party/Google/Client.php');
        require_once(BASEPATH  'application/third_party/Google/Service/Analytics.php');
        session_start();

        $client_id = '<YOUR_CLIENT_ID>'; //Client ID
        $service_account_name = '<YOUR_CLIENT_EMAIL>'; //Email Address 
        $key_file_location = BASEPATH  'application/third_party/Google/<YOUR KEY.p12>'; //key.p12

        $client = new Google_Client();
        $client->setApplicationName("ApplicationName");
        $service = new Google_Service_Analytics($client);

        if (isset($_SESSION['service_token'])) {
          $client->setAccessToken($_SESSION['service_token']);
        }

        $key = file_get_contents($key_file_location);
        $cred = new Google_Auth_AssertionCredentials(
            $service_account_name,
            array(
                'https://www.googleapis.com/auth/analytics',
            ),
            $key,
            'notasecret'
        );
        $client->setAssertionCredentials($cred);
        if($client->getAuth()->isAccessTokenExpired()) {
          $client->getAuth()->refreshTokenWithAssertion($cred);
        }
        $_SESSION['service_token'] = $client->getAccessToken();
        $analytics = new Google_Service_Analytics($client);

        $profileId = "ga:<YOUR_PROFILE_ID>";
        $startDate = date('Y-m-d', strtotime('-31 days')); // 31 days from now
        $endDate = date('Y-m-d'); // todays date

        $metrics = "ga:sessions";

        $optParams = array("dimensions" => "ga:date");
        $results = $analytics->data_ga->get($profileId, $startDate, $endDate, $metrics, $optParams);

        $data['report'] = $results->rows; //To send it to the view later
        $this->view->load('api', $data);

请查看此处此问题的任何解决方案请帮助我解决此问题一个可能的错误,您可以通过查看错误报告来检测:在缺少点运算符“BASEPATH.”application…“后,在require_中。但是如果没有错误信息,就很难判断。如果没有错误信息,则只显示空白页。空白页并不意味着没有记录/跟踪错误。您可以轻松打开错误报告以显示错误消息。否则,错误日志将给您提示,这就是我链接到调试的原因。请查看此处任何解决方案请帮助我解决此问题一个可能的错误,您可以检测到,请查看错误报告:在require_中,一旦您缺少点运算符“BASEPATH.”application…“。但是如果没有错误信息,就很难判断。如果没有错误信息,则只显示空白页。空白页并不意味着没有记录/跟踪错误。您可以轻松打开错误报告以显示错误消息。否则,错误日志将给您提示,这就是为什么我如此链接到调试。
<html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
  google.charts.load('current', {'packages':['corechart']});
  google.charts.setOnLoadCallback(drawChart);

  function drawChart() {
    var data = google.visualization.arrayToDataTable([
      ['Year', 'Sales', 'Expenses'],
      ['2004',  1000,      400],
      ['2005',  1170,      460],
      ['2006',  660,       1120],
      ['2007',  1030,      540]
    ]);

    var options = {
      title: 'Company Performance',
      curveType: 'function',
      legend: { position: 'bottom' }
    };

    var chart = new google.visualization.LineChart(document.getElementById('curve_chart'));

    chart.draw(data, options);
  }
 </script>
 </head>
 <body>
 <div id="curve_chart" style="width: 900px; height: 500px"></div>
 </body>
 </html>