За последние 24 часа нас посетили 20732 программиста и 1135 роботов. Сейчас ищут 319 программистов ...

На локалке всё работает, а на сервере 500 ошыбка

Тема в разделе "Прочие вопросы по PHP", создана пользователем dummphp, 9 фев 2020.

  1. dummphp

    dummphp Новичок

    С нами с:
    9 фев 2020
    Сообщения:
    2
    Симпатии:
    0
    День добрый, прошелся по гайду Google Analytics Api. Сделал на локалке. всё проверил, решил залить на сервер, а там при переходе 500 ошибку постоянно выдает. В чём вообще может быть проблема? Уже голова севеет...

    Спасибо...

    Код (Text):
    1. <?php
    2.  
    3. // Load the Google API PHP Client Library.
    4. require_once __DIR__ . '/vendor/autoload.php';
    5.  
    6. $analytics = initializeAnalytics();
    7. $profile = getFirstProfileId($analytics);
    8. $results = getResults($analytics, $profile);
    9. printResults($results);
    10.  
    11. function initializeAnalytics()
    12. {
    13.   // Creates and returns the Analytics Reporting service object.
    14.  
    15.   // Use the developers console and download your service account
    16.   // credentials in JSON format. Place them in this directory or
    17.   // change the key file location if necessary.
    18.   $KEY_FILE_LOCATION = __DIR__ . '/service-account-credentials.json';
    19.  
    20.   // Create and configure a new client object.
    21.   $client = new Google_Client();
    22.   $client->setApplicationName("Hello Analytics Reporting");
    23.   $client->setAuthConfig($KEY_FILE_LOCATION);
    24.   $client->setScopes(['https://www.googleapis.com/auth/analytics.readonly']);
    25.   $analytics = new Google_Service_Analytics($client);
    26.  
    27.   return $analytics;
    28. }
    29.  
    30. function getFirstProfileId($analytics) {
    31.   // Get the user's first view (profile) ID.
    32.  
    33.   // Get the list of accounts for the authorized user.
    34.   $accounts = $analytics->management_accounts->listManagementAccounts();
    35.  
    36.   if (count($accounts->getItems()) > 0) {
    37.     $items = $accounts->getItems();
    38.     $firstAccountId = $items[0]->getId();
    39.  
    40.     // Get the list of properties for the authorized user.
    41.     $properties = $analytics->management_webproperties
    42.         ->listManagementWebproperties($firstAccountId);
    43.  
    44.     if (count($properties->getItems()) > 0) {
    45.       $items = $properties->getItems();
    46.       $firstPropertyId = $items[0]->getId();
    47.  
    48.       // Get the list of views (profiles) for the authorized user.
    49.       $profiles = $analytics->management_profiles
    50.           ->listManagementProfiles($firstAccountId, $firstPropertyId);
    51.  
    52.       if (count($profiles->getItems()) > 0) {
    53.         $items = $profiles->getItems();
    54.  
    55.         // Return the first view (profile) ID.
    56.         return $items[0]->getId();
    57.  
    58.       } else {
    59.         throw new Exception('No views (profiles) found for this user.');
    60.       }
    61.     } else {
    62.       throw new Exception('No properties found for this user.');
    63.     }
    64.   } else {
    65.     throw new Exception('No accounts found for this user.');
    66.   }
    67. }
    68.  
    69. function getResults($analytics, $profileId) {
    70.   // Calls the Core Reporting API and queries for the number of sessions
    71.   // for the last seven days.
    72.    return $analytics->data_ga->get(
    73.        'ga:' . $profileId,
    74.        '7daysAgo',
    75.        'today',
    76.        'ga:sessions');
    77. }
    78.  
    79. function printResults($results) {
    80.   // Parses the response from the Core Reporting API and prints
    81.   // the profile name and total sessions.
    82.   if (count($results->getRows()) > 0) {
    83.  
    84.     // Get the profile name.
    85.     $profileName = $results->getProfileInfo()->getProfileName();
    86.  
    87.     // Get the entry for the first entry in the first row.
    88.     $rows = $results->getRows();
    89.     $sessions = $rows[0][0];
    90.  
    91.     // Print the results.
    92.     print "First view (profile) found: $profileName\n";
    93.     print "Total sessions: $sessions\n";
    94.   } else {
    95.     print "No results found.\n";
    96.   }
    97. }
     
  2. dummphp

    dummphp Новичок

    С нами с:
    9 фев 2020
    Сообщения:
    2
    Симпатии:
    0

    UPD: сорян, на сервере было виключено display_errors, и не та версия пхп.... Просто фейспелм....