Q:

Missing fields in google service account JSON error while using admin firebase SDK

I am trying to implement real time database of firebase using Kraet admin SDK for PHP 7.0. 
I have installed composer and all the dependencies required for the implementation, but I am facing one error like
**Fatal error: Uncaught Kreait\Firebase\Exception\InvalidArgumentException:
/var/www/html/cabgotel/google-service-account.json could not be parsed to a Service Account:
The following fields are missing/empty in the Service Account specification:
project_id, client_id, client_email, private_key in /var/www/html/cabgotel/vendor/kreait/firebase-php/src/Firebase/ServiceAccount.php:164 Stack trace:
#0 /var/www/html/cabgotel/firebase.php(42): Kreait\Firebase\ServiceAccount::fromJsonFile('/var/www/html/c...')
#1 {main} thrown in /var/www/html/cabgotel/vendor/kreait/firebase-php/src/Firebase/ServiceAccount.php on line 164**

I have downloaded the service account json file and added it in the same directory.  And I even checked the values inside the file to know whether this is for the same firebase project. 
Following is the code I am using for this :
<! DOCTYPE html>
<html>
<head>
    <title></title>

<script src="https://www.gstatic.com/firebasejs/5.8.6/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.8.6/firebase.js"></script>

<script>

  var config = {
    apiKey: "AIzaSyCfGmNSdx5uabtQMGgEjtcz_BL8y_Tm4II",
    authDomain: "auth_domain",
    databaseURL: "my_db_url",
    projectId: "my_project_id",
    storageBucket: "my_project_id_storage_bucket",
    messagingSenderId: "sender_id"
  };
  firebase.initializeApp(config);
</script>

</head>
<body>

</body>
</html>

<? php

error_reporting(E_ALL);
ini_set('display_errors', 1);

require __DIR__.'/vendor/autoload.php';

use Kreait\Firebase;
use Kreait\Firebase\Factory;
use Kreait\Firebase\ServiceAccount;

// This assumes that you have placed the Firebase credentials in the same directory
// as this PHP file. 
$serviceAccount = ServiceAccount::fromJsonFile(__DIR__.'/google-service-account.json');

$firebase = (new Factory)
    ->withServiceAccount($serviceAccount)
    ->withDatabaseUri('https://my_project.firebaseio.com')
    ->create();

$database = $firebase->getDatabase();

$newPost = $database
    ->getReference('https://my_project.firebaseio.com')
    ->push([
        'lan' => '10.77',
        'lat' => '88.99'
    ]);

$newPost->getKey(); // => -KVr5eu8gcTv7_AHb-3-
$newPost->getUri(); // => https://my-project.firebaseio.com/blog/posts/-KVr5eu8gcTv7_AHb-3-

$newPost->getChild('lan')->set('11.211');
$newPost->getValue(); // Fetches the data from the realtime database
$newPost->remove();

Please help. 

A:

There are two files, and they are quite different: 

The google-services.json is for use in Android apps that you send to your users, and merely contains configuration data that the Firebase client SDKs use to find the project on Google's servers.  
The service account JSON, which contains a public and private key pair that allows the code administrative (unrestricted) access to your project. 

The error message to me reads like the code can find the file, but can't find some required fields inside the file.  May sure you download the service account JSON from the Service Accounts tab in the Firebase console, as shown in the documentation on adding Firebase to your app.