hi all
does any one know why this error is occuring and how to remove it
vineet
Just for clarification, which operating system are you running this on, and which version of XAMPP are you using?
xampp 1.8.1
windows xp server pack 3
php 5.4.7
apache 2.4.3
mysql 5.5.27
vineet
Have you managed to confirm that this particular version of xampp is compatible with XP? I can see that the current version definitely isn’t, but I can’t see anything that says 1.8.1 either is or isn’t.
when i simply write on page
echo "hi";
then it works fine and display message as "“hi”,
so this means my version is supported.
But
WHEN I RUN THIS BELOW SCRIPT THEN I RECEIVE ERROR and i have to exit xampp
<?php
function getService()
{
// Creates and returns the Analytics service object.
// Load the Google API PHP Client Library.
require_once 'google-api-client/vendor/autoload.php';
// Create and configure a new client object.
$client = new \Google_Client();
putenv('GOOGLE_APPLICATION_CREDENTIALS=file.json');
$client->useApplicationDefaultCredentials();
$client->addScope('https://www.googleapis.com/auth/analytics.readonly');
return new \Google_Service_Analytics($client);
}
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";
}
}
$analytics = getService();
$profile = getFirstProfileId($analytics);
$results = getResults($analytics, $profile);
printResults($results);
?>
vineet
That’ll help someone with more PHP knowledge than I have.
hope someone will try to figure out the problem and tell us the solution
vineet
What does it say in your PHP
error logs?
hi
can you tell me where should i locate the error logs file in xampp ??
vineet
ok here is the php error log
[07-Aug-2016 07:49:05 UTC] PHP Fatal error: Uncaught exception 'DomainException' with message 'Unable to read the credential file specified by GOOGLE_APPLICATION_CREDENTIALS: file file.json does not exist' in E:\xampp\htdocs\gapi\google-api-client\vendor\google\auth\src\CredentialsLoader.php:73
Stack trace:
#0 E:\xampp\htdocs\gapi\google-api-client\vendor\google\auth\src\ApplicationDefaultCredentials.php(137): Google\Auth\CredentialsLoader::fromEnv()
#1 E:\xampp\htdocs\gapi\google-api-client\src\Google\Client.php(1053): Google\Auth\ApplicationDefaultCredentials::getCredentials('https://www.goo...')
#2 E:\xampp\htdocs\gapi\google-api-client\src\Google\Client.php(354): Google_Client->createApplicationDefaultCredentials()
#3 E:\xampp\htdocs\gapi\google-api-client\src\Google\Client.php(777): Google_Client->authorize()
#4 E:\xampp\htdocs\gapi\google-api-client\src\Google\Service\Resource.php(232): Google_Client->execute(Object(GuzzleHttp\Psr7\Request), 'Google_Service_...')
#5 E:\xampp\htdocs\gapi\google-api-client\vendor\google\apiclient-services\src\Goog in E:\xampp\htdocs\gapi\google-api-client\vendor\google\auth\src\CredentialsLoader.php on line 73
in the first line it says file.json not found.
i replaced it with my json file name.
now no error is being logged in log file.
But i keep getting screen again and again with same message :
apache server has encountered problem and needs to be closed.
and then i have to close it.
why is the error message showing ??
vineet
As you’re using Windows, why not use WAMP instead of XAMP? The current version of WAMP has both PHP 5.6 and PHP 7 available, which are the only versions of PHP now supported
so according to you the problem is php ver 5.4 ??
the latest version doesnt support xp.
do you have any idea which other older version has above 5.4 or 5.5 ??
vineet
also can you tell if wamp and wamp server both are same or different ??
vineet
You could also look at Uniform Server - it’s also a WAMP, but has been packaged so that it will run off a USB memory stick. It’s always worked well for me in the past, though I’ve long since moved onto running things off an Ubuntu server install on its own hardware, or via the same running in a VM.
No, I honestly don’t think it has to do with what you are running on. If the errors go silent, that could be an include problem as this has happened to me before. Copy and paste the entire code for the file CredentialsLoader.php
.
hi spaceshiptrooper
here is the CredentialsLoader.php
<?php
/*
* Copyright 2015 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace Google\Auth;
use Google\Auth\Credentials\ServiceAccountCredentials;
use Google\Auth\Credentials\UserRefreshCredentials;
/**
* CredentialsLoader contains the behaviour used to locate and find default
* credentials files on the file system.
*/
abstract class CredentialsLoader implements FetchAuthTokenInterface
{
const TOKEN_CREDENTIAL_URI = 'https://www.googleapis.com/oauth2/v4/token';
const ENV_VAR = 'GOOGLE_APPLICATION_CREDENTIALS';
const WELL_KNOWN_PATH = 'gcloud/application_default_credentials.json';
const NON_WINDOWS_WELL_KNOWN_PATH_BASE = '.config';
const AUTH_METADATA_KEY = 'Authorization';
/**
* @param string $cause
* @return string
*/
private static function unableToReadEnv($cause)
{
$msg = 'Unable to read the credential file specified by ';
$msg .= ' GOOGLE_APPLICATION_CREDENTIALS: ';
$msg .= $cause;
return $msg;
}
/**
* @return bool
*/
private static function isOnWindows()
{
return strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
}
/**
* Load a JSON key from the path specified in the environment.
*
* Load a JSON key from the path specified in the environment
* variable GOOGLE_APPLICATION_CREDENTIALS. Return null if
* GOOGLE_APPLICATION_CREDENTIALS is not specified.
*
* @return array JSON key | null
*/
public static function fromEnv()
{
$path = getenv(self::ENV_VAR);
if (empty($path)) {
return;
}
if (!file_exists($path)) {
$cause = 'file ' . $path . ' does not exist';
throw new \DomainException(self::unableToReadEnv($cause));
}
$jsonKey = file_get_contents($path);
return json_decode($jsonKey, true);
}
/**
* Load a JSON key from a well known path.
*
* The well known path is OS dependent:
* - windows: %APPDATA%/gcloud/application_default_credentials.json
* - others: $HOME/.config/gcloud/application_default_credentials.json
*
* If the file does not exists, this returns null.
*
* @return array JSON key | null
*/
public static function fromWellKnownFile()
{
$rootEnv = self::isOnWindows() ? 'APPDATA' : 'HOME';
$path = [getenv($rootEnv)];
if (!self::isOnWindows()) {
$path[] = self::NON_WINDOWS_WELL_KNOWN_PATH_BASE;
}
$path[] = self::WELL_KNOWN_PATH;
$path = implode(DIRECTORY_SEPARATOR, $path);
if (!file_exists($path)) {
return;
}
$jsonKey = file_get_contents($path);
return json_decode($jsonKey, true);
}
/**
* Create a new Credentials instance.
*
* @param string|array scope the scope of the access request, expressed
* either as an Array or as a space-delimited String.
* @param array $jsonKey the JSON credentials.
*
* @return ServiceAccountCredentials|UserRefreshCredentials
*/
public static function makeCredentials($scope, array $jsonKey)
{
if (!array_key_exists('type', $jsonKey)) {
throw new \InvalidArgumentException('json key is missing the type field');
}
if ($jsonKey['type'] == 'service_account') {
return new ServiceAccountCredentials($scope, $jsonKey);
} elseif ($jsonKey['type'] == 'authorized_user') {
return new UserRefreshCredentials($scope, $jsonKey);
} else {
throw new \InvalidArgumentException('invalid value in the type field');
}
}
/**
* export a callback function which updates runtime metadata.
*
* @return array updateMetadata function
*/
public function getUpdateMetadataFunc()
{
return array($this, 'updateMetadata');
}
/**
* Updates metadata with the authorization token.
*
* @param array $metadata metadata hashmap
* @param string $authUri optional auth uri
* @param callable $httpHandler callback which delivers psr7 request
*
* @return array updated metadata hashmap
*/
public function updateMetadata(
$metadata,
$authUri = null,
callable $httpHandler = null
) {
$result = $this->fetchAuthToken($httpHandler);
if (!isset($result['access_token'])) {
return $metadata;
}
$metadata_copy = $metadata;
$metadata_copy[self::AUTH_METADATA_KEY] = array('Bearer ' . $result['access_token']);
return $metadata_copy;
}
}
?>
I am not too familiar with Google
APIs, but are you sure you place the Json
file in the correct spot?
hi spaceshiptrooper
i tried many tutorials related to google analytics api client.
they all show same error screen of apache.
this is the link to latest tutorial from which i downloaded script
http://teev.io/blog/google-analytics-api-php
if there is some errors then those errors should get printed on screen. But they are ,making apache to forcily close or exit
i dont if the problem is with api or any file of api client files
as the minimum requirement of the api client is php 5.4 and i have OS as xp , i am unable to install softwares containing php 5.5 or 5.6 version,
again i would say is if there is some errors then those errors should get printed on screen. But they are ,making apache to forcily close or exit
dont know why
vineet
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.