Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/234.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

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 API:消息:文件不存在_Php_Codeigniter_Google Analytics Api_Google Api Php Client - Fatal编程技术网

Php 代码点火器+;Google API:消息:文件不存在

Php 代码点火器+;Google API:消息:文件不存在,php,codeigniter,google-analytics-api,google-api-php-client,Php,Codeigniter,Google Analytics Api,Google Api Php Client,我尝试在codeigniter中实现Google Analytics API。我已按照所有说明将整个Google api下载到第三方文件夹中 require_once(APPPATH . 'third_party/Google/Client.php'); require_once(APPPATH . 'third_party/Google/Service/Analytics.php'); $analytics = initializeAnalytics(); $profile = getFir

我尝试在codeigniter中实现Google Analytics API。我已按照所有说明将整个Google api下载到第三方文件夹中

require_once(APPPATH . 'third_party/Google/Client.php');
require_once(APPPATH . 'third_party/Google/Service/Analytics.php');

$analytics = initializeAnalytics();
$profile = getFirstProfileId($analytics); 
$results = getResults($analytics, $profile);
printResults($results);

function initializeAnalytics()
{
  // Creates and returns the Analytics Reporting service object.

  // Use the developers console and download your service account
  // credentials in JSON format. Place them in this directory or
  // change the key file location if necessary.
  $KEY_FILE_LOCATION = APPPATH . 'third_party/Google/client_secret_626491633530-po28hm9l2ejtbhjdtro8a59ei993gul2.apps.googleusercontent.com';

  // Create and configure a new client object.
  $client = new Google_Client();
  $client->setApplicationName("Yearbase");
  $client->setAuthConfig($KEY_FILE_LOCATION);
  $client->setScopes(['https://www.googleapis.com/auth/analytics.readonly']);
  $analytics = new Google_Service_Analytics($client);

  return $analytics;
}

function getFirstProfileId($analytics) {
  // Get the user's first view (profile) ID.

  // Get the list of accounts for the authorized user.
  $accounts = $analytics->management_accounts->listManagementAccounts();

  if (count($accounts->getItems()) > 0) {
    $items = $accounts->getItems();
    $firstAccountId = $items[0]->getId();

    // Get the list of properties for the authorized user.
    $properties = $analytics->management_webproperties
        ->listManagementWebproperties($firstAccountId);

    if (count($properties->getItems()) > 0) {
      $items = $properties->getItems();
      $firstPropertyId = $items[0]->getId();

      // Get the list of views (profiles) for the authorized user.
      $profiles = $analytics->management_profiles
          ->listManagementProfiles($firstAccountId, $firstPropertyId);

      if (count($profiles->getItems()) > 0) {
        $items = $profiles->getItems();

        // Return the first view (profile) ID.
        return $items[0]->getId();

      } else {
        throw new Exception('No views (profiles) found for this user.');
      }
    } else {
      throw new Exception('No properties found for this user.');
    }
  } else {
    throw new Exception('No accounts found for this user.');
  }
}

function getResults($analytics, $profileId) {
  // Calls the Core Reporting API and queries for the number of sessions
  // for the last seven days.
   return $analytics->data_ga->get(
       'ga:' . $profileId,
       '7daysAgo',
       'today',
       'ga:sessions');
}

function printResults($results) {
  // Parses the response from the Core Reporting API and prints
  // the profile name and total sessions.
  if (count($results->getRows()) > 0) {

    // Get the profile name.
    $profileName = $results->getProfileInfo()->getProfileName();

    // Get the entry for the first entry in the first row.
    $rows = $results->getRows();
    $sessions = $rows[0][0];

    // Print the results.
    print "First view (profile) found: $profileName\n";
    print "Total sessions: $sessions\n";
  } else {
    print "No results found.\n";
  }
}
但我仍然得到:

类型:InvalidArgumentException

消息:文件不存在

文件名:/home/2/y/yearbase/www/app/third_party/Google/Client.php


行号:849

让我们进行一些调试。。。那么,当您执行echo APPPATH时,会得到什么呢?这是您所期望的吗?请检查APPPATH是否是您从google developer console下载的密钥文件(.json文件)的完整路径。APPPATH=/home/2/y/yearbase/www/app/这是appI的确切位置,我已将所需类设置为:require\u once APPPATH第三方/Google/Client.php';require_once(APPPATH.'third_party/Google/Service.php');需要一次(APPPATH.‘third_party/Google/Service/Analytics.php’);让我们做一些调试。。。那么,当您执行echo APPPATH时,会得到什么呢?这是您所期望的吗?请检查APPPATH是否是您从google developer console下载的密钥文件(.json文件)的完整路径。APPPATH=/home/2/y/yearbase/www/app/这是appI的确切位置,我已将所需类设置为:require\u once APPPATH第三方/Google/Client.php';require_once(APPPATH.'third_party/Google/Service.php');需要一次(APPPATH.‘third_party/Google/Service/Analytics.php’);